Is there a convenient way of identifying the parent (not owner) object of a TJSONObject
? The only way I've found so far was to parse the key into its elements and then extract it with string manipulation. Surely there is a better way?
I'm using C++ Builder 10.4 but I'm sure someone who knows the System.JSON Delphi library will be able to help too.
So, as an example I want to change "foobar.name"
from "Spastika"
to "Deon"
in the TJSONObject
parsed from something like this:
{
"foo": "bar",
"foobar": {
"name": "Spastika"
}
}
System.JSON doesn't offer a method to simply change the value of foobar.name
.
(It's hard to believe but its true - if I'm wrong, stop me there and tell me how, please, please, please )
So, let's say I've got a TJSONOBject
called docJSON
that parsed the JSON above.
- When I call
docJSON->RemovePair("foobar.name")
the pair is removed as expected. - HOWEVER:
When I calldocJSON->AddPair("foobar.name", "Deon")
the pair isn't added under thefoobar
object, but in stead as afoobar.name
string in the root ofdocJSON
and the result is this:{ "foo": "bar", "foobar.name": "Deon", "foobar": {} }
So, that is why I need to identify the parent of "foobar.name"
"conveniently" to be able to lateron add the "name"
pair to it after removing it.
All just to change a value in a JSON object - quite painful.