
How to identify location of key in json?

Hello,
I wonder if there is simple way... I am communicating with web server which returns data as json. json xop is amazing and makes it trivial to get data into Igor... The problem is, that depending on how I ask the question, data (identified by specific keys) of interest may be located in different "levels" of complicated nested structure. I would love to be able to find location of specific keys instead of programming all the different structures I can get. Basically, key "title" will always have what I want independently where it is located.
I can traverse the structure and get all keys on each level using json_GetKeys until I find the keys of interest. I know how to do that. But I wonder if I am missing some easier method. My reading of json xop manual did not show anything which would return location of specific key.
Thanks!
Nice to hear that you are finding the JSON XOP useful!
You can use JSON pointer notation to query a single element as in `JSON_GetString(jsonID, '/keyA/keyB/keyC/title')` combined with `ignoreErr = 1` you can quickly check if the string exists or not. If `title` is at arbitrary locations I don't see a way of doing it differently than iterating through all levels with `JSON_GetKeys`.
March 6, 2025 at 02:51 pm - Permalink
OK, this is helpful idea... Thank you!
It will let me test which one of those different structures I am looking at.
March 6, 2025 at 07:41 pm - Permalink