Page 1 of 1

[JSON] How to remove object

Posted: Tue Jun 25, 2019 7:16 pm
by Paradox
I'm testing RemoveJSONElement and RemoveJSONMember not work for my, what remove "lineup" object?

Code: Select all

Define json_text$ = "[{"+Chr(34)+"example"+Chr(34)+":"+Chr(34)+"1"+Chr(34)+","+Chr(34)+"lineup"+Chr(34)+":{"+Chr(34)+"element"+Chr(34)+":"+Chr(34)+"element1"+Chr(34)+"}}]"
ParseJSON(0, json_text$)
If IsJSON(0)
;   RemoveJSONElement(JSONValue(0),1)
;   RemoveJSONMember(JSONValue(0),"lineup")
    Debug ComposeJSON(0)
EndIf

Re: [JSON] How to remove object

Posted: Tue Jun 25, 2019 8:18 pm
by infratec
Hi,

Code: Select all

Define json_text$ = "[{"+Chr(34)+"example"+Chr(34)+":"+Chr(34)+"1"+Chr(34)+","+Chr(34)+"lineup"+Chr(34)+":{"+Chr(34)+"element"+Chr(34)+":"+Chr(34)+"element1"+Chr(34)+"}}]"
ParseJSON(0, json_text$)
If IsJSON(0)
  Debug ComposeJSON(0, #PB_JSON_PrettyPrint)
  ;RemoveJSONElement(JSONValue(0), 0)
  RemoveJSONMember(GetJSONElement(JSONValue(0), 0), "lineup")
  Debug ComposeJSON(0, #PB_JSON_PrettyPrint)
EndIf
you have a json list arround [], so you need to select the element of the list.