Include empty tables in the output of WRITE-JSON and WRITE-XML on a dataset - OpenEdge Development - Products Enhancements - Progress Community

 OpenEdge Development

Include empty tables in the output of WRITE-JSON and WRITE-XML on a dataset

When writing a dasaset with empty tables to JSON or XML, there are omitted. 

I have a dataset, that I want to serialize to JSON. Here is a simplified definition: 

define temp-table ttMain no-undo serialize-name 'main':U
field Id as character
field Name as character.

define temp-table ttSub no-undo serialize-name 'sub':U
field Id as character
field IdMain as character
field Name as character.

define dataset dsMain for ttMain, ttSub
data-relation drMain for ttMain, ttSub
relation-fields (ttMain.Id, ttSub.IdMain) nested.

 

This dataset contains one parent table. And one child table. I populate the parent table, but leave the child table empty.

Current result
I than write it out to JSON, which gives me the following:

{"dsMain": {
"main": [
{
"Id": "123",
"NAME": "name"
}
]
}}

Expected result
My problem is, that I'm missing the Sub table. I would have expected the result to be:

{"dsMain": {
"main": [
{
"Id": "123",
"NAME": "name",
"sub" :  [ ]
}
]
}}

 

I strongly feel this should be an extra option for the write-json and write-xml methods. Because now i'm losing essential information in my JSON.
Or perhaps an option on a temp-table "serialize-empty" or something down that lines

Comments
  • Adding a property to a temp-table is a very messy solution; please ignore that suggestion.

    An option on the WRITE-XML and WRITE-JSON methods is the better option I think.