Jump to content

Help with JSON_OBJECTs - Getting the key by searching the value.


Gayngel
 Share

You are about to reply to a thread that has been inactive for 1521 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

I have a json string that consists of key/value pairs, each pair a JSON_OBJECT. The values are JSON_OBJECTs that contain key/value pairs themselves. So JSON_OBJECTs nested in a JSON_OBJECT. 

e.g: {main_key, {nested_key,nested_value,nested_key,nested_value,nested_key,nested_value},{main_key,{nested_key,nested_value,nested_key,nested_value}},{main_key,{nested_key,nested_value,nested_key,nested_value}}}

Is there a way to get the main_key in the JSON_OBJECT by searching the nested_value? Like can I llListFindList(blah blah blah) - 1 or something similar?

Edited by Gayngel
Link to comment
Share on other sites

If I remember correctly, JSON data is stored as a string, so you could try something like using llSubStringIndex to find what you want and then tracking back to the brace that precedes it and the parent key that precedes that.

There's also llJson2List, so could use that to recurse through the JSON data, and test the resulting lists for your target.

Link to comment
Share on other sites

On 2/24/2020 at 8:49 AM, Gayngel said:

I have a json string that consists of key/value pairs, each pair a JSON_OBJECT. The values are JSON_OBJECTs that contain key/value pairs themselves. So JSON_OBJECTs nested in a JSON_OBJECT. 

e.g: {main_key, {nested_key,nested_value,nested_key,nested_value,nested_key,nested_value},{main_key,{nested_key,nested_value,nested_key,nested_value}},{main_key,{nested_key,nested_value,nested_key,nested_value}}}

Is there a way to get the main_key in the JSON_OBJECT by searching the nested_value? Like can I llListFindList(blah blah blah) - 1 or something similar?

Surely you would just use llJsonGetValue(jsonString,[key]);

Use the list to determine the path you want to take. So if we have :

{ “main_key”: { "nested_key1”: "nested_value1", "nested_key2": "nested_value2" } }

llJsonGetValue(jsonString,[“main_key”,”nested_key2”]);

Note : I have probably fluffed it up as writing it on my phone but code to that effect 😅

Edited by ItHadToComeToThis
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 1521 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...