Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: decoding a JSON object

by kcott (Archbishop)
on Nov 23, 2022 at 02:52 UTC ( [id://11148314]=note: print w/replies, xml ) Need Help??


in reply to decoding a JSON object

G'day anautismobserver,

Decode (to a Perl data structure) using JSON. If you also have JSON::XS installed, it will run faster. You can use JSON::XS directly, but some users who maybe can't compile XS code will not be able to run your script. [See Update below]

Once you have the JSON data in a Perl format, getting the wanted values is pretty straightforward. See "perldsc - Perl Data Structures Cookbook" if you don't know how to do this.

Update: I took "Below is code that returns a JSON object." on face value and, in line with the title, "decoding a JSON object", provided a generic response on how to achieve that. I think you can be forgiven for assuming a method called json() returns JSON; however, that's not the case — see ++1nickt's explanation.

— Ken

Replies are listed 'Best First'.
Re^2: decoding a JSON object
by haukex (Archbishop) on Nov 23, 2022 at 06:22 UTC

    Sorry, but the first paragraph is not applicable here - Mojo has JSON decoding already built in, and $json_food will already contain decoded JSON due to the ->json call.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-24 13:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found