[fpc-pascal] Finding the path of a TJSONObject?
Michael Van Canneyt
michael at freepascal.org
Thu Jun 16 18:09:02 CEST 2016
On Thu, 16 Jun 2016, Graeme Geldenhuys wrote:
> On 2016-06-16 16:48, Michael Van Canneyt wrote:
>> You can't.
>> There is no reference to the owner.
> After I posted the message I took a closer look at the fpjson code and
> came to the same conclusion. Apparently the same thing is true for other
> JSON implementations too.
> This is rather baffling - why can't you traverse backwards? It is such
> a logical thing with any hierarchy of data. And judging by the amount of
> questions on StackOverflow and other places on the Internet, it seems
> many people would like a .Parent property too.
> Would a patch for that be accepted?
It increases memory usage, which I want to be kept to an absolute minimum,
and I believe the use case for this kind of request to be very marginal.
In 99% of cases you will do the JSONPath() approach using find.
I realize someone is out of luck if he is in the 1% marginal cases, but
I really don't want to clutter the implementation for this.
There are hooks to instantiate custom descendent types if someone is so
inclined, and this can be used to instantiate types that have a parent.
I see more use in a SAX-kind of parser, which could be used to construct a 'map'
of the data in case such a thing is needed, which could be used for the
purpose of finding a parent. This is still on my todo list.
More information about the fpc-pascal