I need a json object output in a particular format and 4D's new datastore and 
collections do this out of the box in 3 lines of code for me.  It's almost 
magical.

$oRecs:=ds.Complex.query("Domain_ID = :1";_Domain_ID)
$coll:=$oRecs.toCollection("ID, Name, Facilities.ID, Facilities.Name")
$vtReturn:=JSON Stringify($coll)

The problem I have is the Javascript libraries I'm using that requires the data 
needs the names of the JSON elements to be named in a particular way.  Is there 
a way to tell my collection rename ID to key and Name to label etc?

So 4D is currently outputting this.

[
        {
                "ID": 901,
                "Name": "MP",
                "Facilities": [
                        {
                                "ID": 1159,
                                "Name": "MP:North"
                        },
                        {
                                "ID": 1160,
                                "Name": "MP:South"
                        }
                ]
        }
]



But what I need is this.

[
        {
                "key": 901,
                "label": "MP",
                "children": [
                        {
                                "key": 1159,
                                "label": "MP:North"
                        },
                        {
                                " key ": 1160,
                                "label": "MP:South"
                        }
                ]
        }
]

I know I could just do a replace in string but this feels like the wrong way to 
go at this.

Thanks
Justin Will
**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[email protected]
**********************************************************************

Reply via email to