Retrieving JSON object identifier/name

This is my JSON:

  "BROWSER": {
    "WINDOWTOP": " 327 ",
    "WINDOWLEFT": " 261 ",
    "WINDOWHEIGHT": " 534 ",
    "WINDOWWIDTH": " 1008 "

For example: I have DynamicObject pointing to the “WINDOWTOP” property …

 NamedValueSet& browserProps = browserObj->getProperties();
 DynamicObject* object = browserProps ["WINDOWTOP"].getDynamicObject();`

Is there a way to save and access object’s “TAG/IDENTIFIER” name (which is “WINDOWTOP”) at later stage. For example, i have only pointer to this dynamic object and i want to check it’s name!?!

As i understand, i can access it’s name only when treated as property from NamedValueSet …

String name = browserProps.getName (0).asString();

And i know JSON properties can be accessed&checked only via parent object, but something similar like JUCE XML “hasName” method would be very handy.

I might be missing something obvious here … any ideas?

For better or worse, the DynamicObject class doesn’t store this kind of information.

An alternative approach would be to use a ValueTree to manage the properties in a named fashion. This will give you a bunch of features “for free” so as to manage saving/reloading UI and local file bits, as well as undo/redo, by hooking them to a CachedValue or keeping an eye out with a ValueTree::Listener. Also, var (which is what ValueTree stores) will give you some form of type-safety so you don’t have to set strings when you seem to want integers (which JSON supports anyways!).

1 Like