in reply to search json for key with particular value
Here is some code that does the recursion and returns all objects that include a "componentId". I marked the line where you would edit the logic to only return objects that have componentId whose value matches.
I am not a JSON expert, so there may be a way using the JSON module or helper module to do a more efficient recursive search than my manual answer. I yield to wiser monks.
--
edit: JSON module will be faster if you have installed JSON::XS, because it will try to use that if possible.
edit2: updated code to use the OP-style data, as interpreted by hippo, rather than my proprietary data; also fixed post and code so "componentId" had correct case on the "d"
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: search json for key with particular value
by rahulruns (Scribe) on Dec 16, 2020 at 14:55 UTC |