Salesforce

Does JSON serialization of a ProDataSet support representing a single nested child record as a simple string instead of an array ?

« Go Back

Information

 
TitleDoes JSON serialization of a ProDataSet support representing a single nested child record as a simple string instead of an array ?
URL Name000057352
Article Number000136923
EnvironmentProduct: OpenEdge
Version: 11.x, 12.x
OS: All supported platforms
Other: ProDataSet, JSON
Question/Problem Description
Consider a dataset where each record in a parent table has at most a single child record

Writing out this dataset as JSON using WRITE-JSON() method will create an Array for the single child records. Example:

{"jsonOutput": {
  "Vehic": [{ "Brand": "OPEL", "RegNumber": "AB-123-CD", "Model": "Insigna", "Driver": [ { "Name": "Alice Cooper", "LicenceNum": "1234567890123" } ] },
            { "Brand": "RENAULT", "RegNumber": "CD-456-EF", "Model": "Megane Scenic", "Driver": [ { "Name": "Ozzy Osbourne", "LicenceNum": "1357913579135" } ] },
            { "Brand": "AUDI", "RegNumber": "EF-789-GH", "Model": "A6 AllRoad", "Driver": [ { "Name": "Robert Plant", "LicenceNum": "2468024680246" } ] }
  ]
}}

JSON allows embedding the child object as a simple string as well, which would be the smallest possible notation. Continuing above example, that would look like:

{"jsonOutput": {
  "Vehic": [{ "Brand": "OPEL", "RegNumber": "AB-123-CD", "Model": "Insigna", "Driver": { "Name": "Alice Cooper", "LicenceNum": "1234567890123" } },
            { "Brand": "RENAULT", "RegNumber": "CD-456-EF", "Model": "Megane Scenic", "Driver": { "Name": "Ozzy Osbourne", "LicenceNum": "1357913579135" } },
            { "Brand": "AUDI", "RegNumber": "EF-789-GH", "Model": "A6 AllRoad", "Driver": { "Name": "Robert Plant", "LicenceNum": "2468024680246" } }
  ]
}}

(Note the square brackets from the array notation are removed)

Is there a way for WRITE-JSON to avoid creating arrays for the single child records ?
 
Steps to Reproduce
Clarifying Information
Attached .zip file contains samples.
 
Error MessageError parsing JSON: unexpected token: String. (15360)
Error parsing JSON: expected brace, but found bracket. (15358)
Defect Number
Enhancement Number
Cause
Resolution
This is currently not possible.

READ-JSON() expects any nested child records to be represented as an Array. Any other representation will trigger one of the following errors : 
Error parsing JSON: unexpected token: String. (15360)
Error parsing JSON: expected brace, but found bracket. (15358)

Likewise, WRITE-JSON() will always write child records as an Array, even if that results in an Array of only one element/string.

It was determined that the Progress Product is functioning as designed.
 
An enhancement to the product can be requested through the Progress Community via an Ideas submission.  Customer feedback is valuable and Idea submissions are monitored by our Product Management team.  Enhancement requests are reviewed during the planning phase of each new product release and a list of the enhancements chosen for implementation can be found in the Release Notes documents that accompany each release.  Once an Idea is submitted the Progress Software Community will have the opportunity to comment on and vote for the Idea.
 
For detailed information on how to submit an Idea, please refer to Knowledge Base article  How to submit an idea for a Progress product enhancement
Workaround
Build the JSON manually, using the built-in Progress.Json.* classes.
Refer to the "Integration and General Business Interfaces: Working with JSON" manual for more information.
Notes
References to Other Documentation:
Integration and General Business Interfaces: Working with JSON, chapter "Parsing and Serializing JSON Objects and Arrays"

Progress Article(s):
 How to submit an idea for a Progress product enhancement

Please note that json-read and json-write are narrowly focused for read in and writing out json that is compatible with temp-tables and prodatasets. For dealing with more generic json, please see the following:
JsonArray
https://documentation.progress.com/output/ua/OpenEdge_latest/index.html#page/dvref/progress.json.objectmodel.jsonarray-class.html

JsonObject
https://documentation.progress.com/output/ua/OpenEdge_latest/index.html#page/dvref/progress.json.objectmodel.jsonobject-class.html


These classes provide a set of methods that allow the reading in and writing out of json, over which the developer has full control.
Keyword Phrase
Last Modified Date4/30/2021 2:52 PM

Powered by