Update values ​​for JSON file why were the other members lost ?

Just starting out? Need help? Post your questions and find answers here.
hdt888
User
User
Posts: 48
Joined: Sun Jul 07, 2024 8:42 am

Update values ​​for JSON file why were the other members lost ?

Post by hdt888 »

I have successfully added the "FastMode" member and set its value to "OK" for the settings.json file which does not exist yet.

But when the settings.json file already exists, I am in the situation:

+ if the "FastMode" member does not exist yet.
+ if the value of the "FastMode" member already exists and should be set to "OK".

I tried using:

Code: Select all

LoadJSON(0, "D:\settings.json"),
but when saving:

Code: Select all

SaveJSON(0, "D:\settings.json", #PB_JSON_PrettyPrint)
the "Status": "20" member is lost.

How to update this "OK" value to the member "FastMode" ?.

Code: Select all

{
"FastMode": "Not OK",
"Status": "20"
}
PB 5.x + 6.x + Win10. Feel the ...Pure... Power.
User avatar
the.weavster
Addict
Addict
Posts: 1580
Joined: Thu Jul 03, 2003 6:53 pm
Location: England

Re: Update values ​​for JSON file why were the other members lost ?

Post by the.weavster »

Code: Select all

Procedure json_get_member(js, key$)
  Protected nMember = GetJSONMember(js, key$)
  If Not nMember
    nMember = AddJSONMember(js, key$)
  EndIf
  ProcedureReturn nMember
EndProcedure

LoadJSON(0, "D:\settings.json")
SetJSONString(json_get_member(JSONValue(0), "FastMode"), "OK")
SaveJSON(0, "D:\settings.json", #PB_JSON_PrettyPrint)
Post Reply