Feedback
Did this article resolve your question/issue?

   

Article

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

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.
Last Modified Date4/30/2021 2:52 PM
Attachment 
Files 1. json.zip
Disclaimer The origins of the information on this site may be internal or external to Progress Software Corporation (“Progress”). Progress Software Corporation makes all reasonable efforts to verify this information. However, the information provided is for your information only. Progress Software Corporation makes no explicit or implied claims to the validity of this information.

Any sample code provided on this site is not supported under any Progress support program or service. The sample code is provided on an "AS IS" basis. Progress makes no warranties, express or implied, and disclaims all implied warranties including, without limitation, the implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample code is borne by the user. In no event shall Progress, its employees, or anyone else involved in the creation, production, or delivery of the code be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample code, even if Progress has been advised of the possibility of such damages.