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!
I came across this need myself just yesterday.
The universe is a strange thing.
Of course this is very barebones and some code should probably be added to check if the keys exist etc. but this should do in a pinch. To make it more re-usable a recursive function or a loop can be used to set values that are more deeply nested.