#1 2015-11-12 01:44:56

wienani
Member
Registered: 2012-08-31
Posts: 29

Current Level only _JSON

Is there any options for _JSON for resulting current level from nested json source ? i mean no nested result just current level. sorry my bad english.

Source :
{
   "aaa": 0,
   "bbb": 1,
   "ccc" : {
       c1: 0,
       c2: 1,
       c3: {
          c31: 0,
          c32: 1
       }
    }
}

Output expected for "var.ccc"
{
   "c1": 0,
   "c2": 1
}

Offline

#2 2015-11-12 07:11:57

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,658
Website

Re: Current Level only _JSON

You can try the "Reduce" method.

Offline

#3 2015-11-17 14:03:56

wienani
Member
Registered: 2012-08-31
Posts: 29

Re: Current Level only _JSON

Sorry ab, I only find Reduce method in TDocVariantData, but the result still have nested inside.

begin
  fVar := _JSon('{"aaa":0,"bbb":1,"ccc":{c1:0,c2:1,c3:{c31:0,c32:1}}}');
  _Safe(fVar)^.Reduce(['ccc'], false, fOut);
  showmessage(fOut.tojson);
end

Result still have nested 'c3'

 {"ccc":{c1:0,c2:1,c3:{c31:0,c32:1}}}

I need a function maybe look like

showmessage(fVar.ccc.CurrentLevel);

ccc   -> {c1:0,c2:1}
root* -> {"aaa":0,"bbb":1}
c3    -> {c31:0,c32:1}

Offline

#4 2015-11-17 14:39:02

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,658
Website

Re: Current Level only _JSON

Navigate within the TDocVariantData.Values[] properties, using _Safe() to retrieve any nested object, and only getting what you need.

Your need is so specific we perhaps won't include it within the main TDocVariantData object.

Offline

Board footer

Powered by FluxBB