LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Unflatten From JSON Type Mismatch Problem

I know there are a few threads dealing with similar questions, but this one is a bit different, or at least I haven't found a solution.

 

I'm trying to unflatten a JSON data feed (COVID19) from https://corona-api.com/countries/US. According to the instruction, https://about-corona.net/documentation, the JSON is in this style:

 

{
    "data": {
        "coordinates": {
            "latitude": 33, // Float
            "longitude": 65 // Float
        },
        "name": "Afghanistan", // String, human readable
        "code": "AF", // String, ISO 3166-1 alpha-2
        "population": 80000000 // Integer or null
        "updated_at": "2020-03-20T22:38:42.275Z", // Date
        "today": {
          "deaths": 0,  // Int or null
          "confirmed": 2  // Int or null
        },
        "latest_data": {
            "deaths": 0, // Int or null
            "confirmed": 100, // Int or null
            "recovered": 50, // Int or null
            "critical": 0, // Int or null
            "calculated": {
                "death_rate": 0, // Float (%) or null
                "recovery_rate": 50, // Float (%) or null
                "recovered_vs_death_ratio": 0, // Float (%) or null
                "cases_per_million_population": 0.6 // Float (%) or null
            }
        },
        "timeline": [
            {
                "updated_at": "2020-03-20T20:44:58.707Z", // Date
                "date": "2020-03-20", // Date
                "deaths": 0, // Int or null
                "confirmed": 100, // Int or null
                "recovered": 50, // Int or null
                "active": 50, // Int or null
                "new_confirmed": 40, // Int or null
                "new_recovered": 30, // Int or null
                "new_deaths": 0, // Int or null
                "is_in_progress": true // Boolean
            },
            {
                "updated_at": "2020-03-19T19:13:08.000Z", // Date
                "date": "2020-03-19", // Date
                "deaths": 0, // Int or null
                "confirmed": 60, // Int or null
                "recovered": 20, // Int or null
                "active": 40, // Int or null
                "new_confirmed": 20, // Int or null
                "new_recovered": 10, // Int or null
                "new_deaths": 0, // Int or null
            },
            {
              ...
            },
        ]
    },
    "_cacheHit": false
}

My problem is the "timeline" part, which is a cluster array. But the structure of the first element is different than the remaining elements. I've created a typedef ctl matched the "remaining" part, but I don't know how to match the first element. 

 

Any help will be appreciated.

 

Dahai

 

 

0 Kudos
Message 1 of 3
(934 Views)

Good job on the control, works like a champ for me.  Just about every COVID site I have used for data finds some way to be truly annoying, and tacking an extra member into the first timeline object is yet another example.

 

Not the cleanest solution, but if you really want that 'is_in_progress' element you could parse for it alone using the path array ['data', 'timeline','0','is_in_progress'] with a boolean wired to the default/datatype terminal.  Parsing the same string twice is usually a bummer performance-wise, but with a path wired the second one should be pretty quick.

Message 2 of 3
(904 Views)

Yes, it works like a charm. Thanks.

 

Dahai

0 Kudos
Message 3 of 3
(894 Views)