assurance-tunnel
assurance-tunnel
assurance-tunnel
assurance-tunnel

[ANSWERED] JSON Parser Beta and nested square brackets


  • Beta Platinum

    @Mark,

    I have hit a hurdle with the new JSON Parser and need one more piece of advice.

    In the JSON data set below, returned from a URL, nested square brackets are used. Can you provide a tip for parsing this through the JSON Parser actor? It reports there are 2 items but I don't get how to parse through the square brackets for the data output. I have been unable to parse the JSON directly without stripping off the square brackets first with aa Text Parser. DynamicDataV2.1.izz

    Best Wishes

    Russell

    [{"page":1,"pages":1,"per_page":"50","total":1}
    ,[{"id":"POL","iso2Code":"PL"
    ,"name":"Poland"
    ,"region":{"id":"ECS"
    ,"iso2code":"Z7"
    ,"value":"Europe & Central Asia"
    },"adminregion":{"id":""
    ,"iso2code":""
    ,"value":""
    },"incomeLevel":{"id":"HIC"
    ,"iso2code":"XD
    ","value":"High income"
    },"lendingType"{"id":"IBD"
    ,"iso2code":"XF"
    ,"value":"IBRD"
    },"capitalCity":"Warsaw"
    ,"longitude":"21.02"
    ,"latitude":"52.26"}]]



  • Dear @bonemap 

    You found a bug. I've fixed and uploaded v0.9.1 in the original JSON Parser thread. There are also updated instructions on how to access elements of an array by index.

    Best Wishes,
    Mark



  • Also, here's a patch showing your full structure decoded using the updated actor.

    test-json-index.izz

    Best Wishes,
    Mark



  • @mark I love this, something I have ben waiting for. I have one issue, a lot of sites will return time in unix timestamps. I have made a javascript actor to parse the timestamps and output a human readable date time string. However the timestamps I am getting are in milliseconds and are truncated by the limitation of the type I am guessing (I think they should be int64?).

    Is it possible to allow these types to be passed from the json parser? Or if it is already possible, is there a trick to it?

    Fred 



  • @fred said:

    I have made a javascript actor to parse the timestamps and output a human readable date time string. However the timestamps I am getting are in milliseconds and are truncated by the limitation of the type I am guessing (I think they should be int64?).

    According to this article about Javascript integers:

    JavaScript, by specification, does not know about integers (with the exception of recently introduced BigInts). It only knows IEEE doubles. But many operations are based on integers, just think of for loops. All JavaScript engines have a special representation for integers. V8 has so called Smis, small integers.

    Now, I just tried using a BigInt in our Javascript actor -- but it ended up crashing Isadora. :-(

    (Apparently our version of v8 knows about BigInts because I didn't get a syntax error, but something else went wrong. I'll have to look into that.)

    Let me get clear on what you mean by "unix timestamps" -- do you mean the number of seconds since midnight Jan 1, 1970? I guess not since these do not include milliseconds. What do you mean?

    But what if you simply divided your millisecond integer values by 1000.0 to get seconds instead? Does that address the problem?

    Well, I think I need an example patch or something to answer this more effectively.

    Best Wishes,
    Mark



  • @mark yes, I am talking about unix timestamps - the number of seconds since midnight Jan 1, 1970, this is how pretty much every web api deals with dates and times. The problem I am having is not getting the timestamp into the Javascript actor but getting it out of the JSON parser.

    For example when I check the web api I am using I get the first timestamp as : 1585207161600, but this element is output from the JSON parser as 364071376, if I use another method to see the results and search them there is nowhere that I find 364071376 (just to check if I made a mistake parsing).

    I have made a very simple sample patch based on the example above, if I change any of the values of a JSON attribute to 1585207161600, it will output 364071376 from the parser.JSON Parse timestamp error.izz