Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^3: parse json data with underscore symbol

by amaa11 (Initiate)
on Aug 18, 2018 at 07:43 UTC ( [id://1220568]=note: print w/replies, xml ) Need Help??


in reply to Re^2: parse json data with underscore symbol
in thread parse json data with underscore symbol

Dear kevbot,
Yes I updated the all post as you asked
still have a small problem when I print the second element in the array
print 'ge= ' . $decoded->{_embded}{stes}[1]{ge}, "\n"
I got this error.
Use of uninitialized value in concatenation (.) or string

Replies are listed 'Best First'.
Re^4: parse json data with underscore symbol
by kevbot (Vicar) on Aug 18, 2018 at 07:51 UTC
    The array reference given by $decoded->{_embded}{stes} only has one element so the data is at index 0. Try this, $decoded->{_embded}{stes}[0]{ge}

      Dear Kevbot, Thanks a lot for providing me these info.
      Just imagine that I have a very long of the data (Json) as i posted in the post. And I wand print all what I want by a loop to parse all the data.
      Can you suggest any module or way to do that??
      Regards

        Hello amaa11,

        It's difficult to give advice because the code you need to write will be highly dependent on the data structure returned by decode_json, which is highly dependent on the structure of your JSON string.

        If you are going to be extracting data from complex JSON strings, then it may be helpful to use a module that helps you extract the data (without having to worry about the perl data structure). One such module is JSON::Path. It lets your write a JSONPath string to extract the data. This way you can write a JSONPath string that will extract only the portion of data that you are interested in and it will reduce the amount of perl code you need to write. I have converted your script of use JSON::Path to give you an example to work from.

        If you choose to use this module, I recommend you carefully read the documentation for the JSON::Path and JSONPath - XPath for JSON.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (3)
As of 2024-03-28 18:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found