This file is parsed into a var object via JSON::parse() function.
I have the need to modify just a simple named property, but, I could not design a suitable method for it.
At this point I have to :
iterate the var object to locate the named property
modify its value directly into the var ojbect
turn the var object again into JSON string
Any suggestion will be apreciated too much.
Thanks in advance
PS. I didn’t find any related topic in the forum that can met this issue
It helps to spell out, what your structure in json is. In your case it is an array of objects. So you can do:
var json;
if (json.isArray()) {
for (auto item : *json.getArray()) {
if (auto object = item.getDynamicObject())
if (object->hasProperty ("Valid"))
object->setProperty ("Valid", false);
}
}
Haven’t tested (too much work to create the json you have…), but should work
N.B. because you use getDynamicObject it doesn’t matter, if the var is a copy or not, because they reference a DynamicObject, which is a SharedObject referenced from the var.
It is closely to my issuet, but focuses on how to add a property, rather than locating and changing it.
@daniel
No, it does not work. I think, an array in JSON is represented by a pair of brakets .
@all
I feel that what I want is a recursively callled function, to traverse the whole var object, examning each contained DynamicObject or NamedProperty, if it contains the property that I need to modify.
I thing it can be seems like this:
I am searching many hours the Juce forum and Juce code/documentation, but I could’nt find the pieces (code, functions or whatever. .) to implement a procedure like the one above.
var json;
if (auto object = json.getDynamicObject)
for (auto property : object->getProperties())
if (auto sub = object [property].getDynamicObject())
if (sub->hasProperty ("Valid"))
sub->setProperty ("Valid", false):