How to parse a list of elements in JSON individually using route

djtoshi182's icon

hello.

* trying other methods

instead using js parser, I am using dict, maxurl, dct.unpack
my reply below is the new inquiry.

djtoshi182's icon

Hello.
I have been looking for a solution using dict to parse json.
The multiple lists is under "result", each list has "seq"
I'd like to parse into each dictionary with its queries.
If I get rid of "result", only thefirst list comes out.

or, should I create json with replacing "result" with each "seq"?
How to parse multiple obj output dict?

result obj:dictionary:u833004823 obj:dictionary:u759004824 obj:dictionary:u470004825

the json comes like this,

{
"result" : [         {
    "seq" : "2",
    "query" : "2601:801:201:7c50:d450:1f9:e918:2e15",
    "status" : "success",
    "country" : "United States",
    "countrycode" : "US",
    "region" : "CA",
    "regionname" : "California",
    "city" : "Sacramento",
    "zip" : "94203",
    "lat" : "38.5816",
    "lon" : "-121.494",
    "timezone" : "America/Los_Angeles",
    "isp" : "Comcast Cable Communications, LLC",
    "org" : "Comcast Cable Communications, LLC",
    "toas" : "AS7922 COMCAST-7922 - Comcast Cable Communications, LLC",
    "cdate" : "2020-02-23 16:54:27"
    }
,     {
    "seq" : "1",
    "query" : "",
    "status" : "",
    "country" : "",
    "countrycode" : "",
    "region" : "",
    "regionname" : "",
    "city" : "",
    "zip" : "",
    "lat" : "",
    "lon" : "",
    "timezone" : "",
    "isp" : "",
    "org" : "",
    "toas" : "",
    "cdate" : "2020-02-23 16:53:05"
    }
 ]
}
kLSDiz's icon

This is the simplest way that crossed my mind:

Max Patch
Copy patch and select New From Clipboard in Max.


kLSDiz's icon

How do you want to group them?

djtoshi182's icon

It worked! I used pack and they are printed in each groups.
I need to insert each group from print to each row of jit.cellblock
How to divide them into separate lists at least?

Thank you for the help!

djtoshi182's icon

I can use 'getsize result' to know how many lists there are.

djtoshi182's icon

Found it.

t b l
counter
join
coll

kLSDiz's icon

If you want to display data in cellblock, you can go this way:

Max Patch
Copy patch and select New From Clipboard in Max.

A bit clunkier, but still doable. Max is not the best tool to display tabular data. If you want to actually use the data for some interactive/audio/visual processes, it may be easier.

djtoshi182's icon

Thank you!

djtoshi182's icon

Following up KLSDIZ's example, I have a weird issue that the dict.iter only can process maximum 11 elements in the list, rest of it cause error with "doesn't understand".
I find there's nothing wrong with the incoming list. Any solution to this?

djtoshi182's icon

Fixed using get message to dict directly.

Liam Joy Niemeijer's icon

Hi there, could you share your patch maybe for me to see how you did it? Thanks!

yaniki's icon