Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re: search json for key with particular value

by pryrt (Monsignor)
on Dec 15, 2020 at 14:46 UTC ( #11125235=note: print w/replies, xml ) Need Help??

in reply to search json for key with particular value

The way I would approach the task is to recurse into each object, and return the current object if it has a "componentId" key whose value matches your restriction.

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

    Thank you for your answer I was thinking of recursing structure but was looking if there is any other possibility except recursing structure

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11125235]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2021-02-24 20:50 GMT
Find Nodes?
    Voting Booth?

    No recent polls found