- Igor Perisic
- PowerBuilder
- Tuesday, 17 January 2023 08:22 PM UTC
Hi,
I am working on a few different things at the moment, JSON being one of them. I was wondering how can I edit my JSON file that has nested objects (i think that's the correct the term). In other words, a JSON structure that looks like this.
{
"Application":
{
"trace": "yes",
"timeout": "4",
"appName": "test"
},
"Database":
{
"username": "UserTest",
"password": "1234",
"server": "myserver"
}
}
My goal is to change the "timeout" value that is inside the "application" object for example. I am currently using this code
jsonString = create JsonPackage
checkError = jsonString.LoadFile(Appl + ".json")
if Len(checkError) = 0 then
result = jsonString.SetValue("timeout","12", false)
if result = 1 then
jsonString.SaveToFile(Appl + ".json", EncodingANSI!)
end if
end if
But this doesn't edit the "timeout" value inside the "application" object, instead it just creates a new object after "Database". I figure out how to read nested objects using, "GetRootItem(), "GetItemObject(), GetItemString()" but I cannot figure out how to set values the values. There doesn't seem to be a complimentary "SetItemString()" function to those Get functions. I can't find anything in the documentation.
Thanks!
Find Questions by Tag
Helpful?
If a reply or comment is helpful for you, please don’t hesitate to click the Helpful button. This action is further confirmation of their invaluable contribution to the Appeon Community.