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.