Create JSON with dynamic key (Progress 4GL)

Posted by osama on 12-Oct-2017 03:48

I have a dataset defined for 2 temp-tables linked with some field (lets say : item). For example:

define temp-table items no-undo
  field item as char.

define temp-table customer no-undo
  field item     as char serialize-hidden
  field custname as char
  field price    as dec.

define dataset dsitemcust for items,customer
  data-relation dr1 for items,customer relation-fields(item,item) nested.

This gives the json output like this:

{
  "items": [
     {
        "item": "abc_item",
        "customer": [
           {
              "custname": "uvw_cust",
              "price": 123
           },
           {
              "custname": "xyz_cust",
              "price": 234
           }, 
           ....
        ]
     },
     {
        "item": "def_item",
        "custname": [{},{},...]
     }
     ...
     ]
}

But i want to get something like this: [item as key and, custname and price as value (in array of object where custnum is key again)]

{ "abc_item" : [{"uvw_cust" : 123}, {"xyz_cust" : 234}, ...],
  "def_item" : [{}, .. ],
  ..
}

10.2B doesn't seem to support JsonObject. But i need it in 10.2B.
Is this possible/achievable in Progress openedge (Progress version: 10.2B) ? 

All Replies

Posted by Peter Judge on 12-Oct-2017 08:08

You could write your own code to do the serialization to JSON – basically implement the JsonObject functionality. You could alsio just write to a longchar:
lcJson = lcJson + “~{“ + keyField + …
 
Which is kludgy but works. If you wrap that writing in a class (ideally)  or a persistent procedure you can replace it with calls to JsonObejct when you upgrade).

This thread is closed