It doesn’t need a special class! ‘var’ does the job of representing JSON/Javascript objects, so to create JSON, you just create a var. (Sorry, I thought that would be obvious by the way JSON::parse returns a var!)
ValueTree is different - its structure is analogous to XML, which can’t be mapped directly onto JSON.
Perhaps we need some examples for how to create vars that have nested structures, similar to the text examples in this thread. Could ya take a minute and help out the users with some examples?
I did a kludgy patch to make that work, here attached.
The problem is I cannot return a const var getNullValueReference(), because you cannot assign something to it.
As a workaround I create a static non const var, that swallows the assigned content.
The language just doesn’t lend itself to something like this. I don’t know if the standards committee would ever consider adding something like operator[]= but without something like that, trying to cleanly implement assignment in this way is just nasty, involving messy intermediary objects, caveats for the way it should be used, and performance penalties.
But I think there is nothing wrong with returning a non const reference to the properties, so the operator= already does the job…
Also the non const version is only called, if an assignement is to be made, otherwise it would choose the const version? So it would be ok to add a var() for assigning the value to.
The only problem is, if the var is not a DynamicObject. Then you are already in the assignement, you can’t bail out…