LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

JSON Parser File Path Not Found

Solved!
Go to solution

So I have a JSON file from which I'm trying to extract data, but I cannot get the correct file path. I'm using Unflatten from JSON

 

The JSON string looks something like this:

 

{"latitude":32.78,"longitude":-96.81,"timezone":"America/Chicago","offset":-5,
"currently":{"time":1478744444, "summary":"Mostly cloudy"},
"minutely":{},
"hourly":{"summary":"Rain",
"icon":"rain",
"data":[{"time":1478744555,"summary":"Cloudy","temperature":60.55,"windSpeed":14.5}
{"time":1478745555,"summary":"Mildly cloudy","temperature":60.00,"windSpeed":13.5}]},
"daily":{},
"flags":{}
}

 There is much more in the actual string, but the important part is the hourly data, which is divided into 48 different pieces for 48 hours. I know that I can get the "time" and "summary" from the "currently" portion, but whenever I try to get something from "hourly" or "hourly/data" I get this error: "LabVIEW:  The path cannot be found in the JSON string."

 

I can get the "currently" info like this: CurrentlyLabview.JPGThis is just showing that the path is very simple, just "currently/time" and it works.

 

But trying to do the same thing doesn't work with the array of objects: HourlyData.JPG

I've also tried making the type and defaults the same as what's in the "data" array elements, but the error is still the same.

 

So is there a way to separate each of the time slices in "data", or to extract everything that's in the "hourly" block and then use the Unflatten JSON function on that again?

0 Kudos
Message 1 of 4
(5,194 Views)

Please include a Snippet of your code, or attach your VIs, so that we can better assist you. We are here to help, but won't spend all that extra time recreating your code from scratch.

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


0 Kudos
Message 2 of 4
(5,183 Views)
Solution
Accepted by topic author LukeEm

You need to include the array index in your path. The square brackets in the json data indicate an array so you need to do something like the following:

JSON Array.png

 

For some reason I'm getting a "LabVIEW:  The JSON string is invalid. JSON strings must be encoded in UTF-8 and must conform to the JSON grammar." error but that might just be because of the copy+paste of the JSON string.

 

Oh...it's missing the comma between the array elements. Add a comma after the windSpeed":14.5} at the end of the 6th line.

 

In your second example, you should have made the cluster into an array of clusters containing 3 numeric elements - then that should have worked. It takes a bit of getting used to understanding how to convert JSON structures to LV Clusters.


LabVIEW Champion, CLA, CLED, CTD
(blog)
Message 3 of 4
(5,149 Views)

Hey Guys, My json data is something like this
{
"Currents" : {
"I1" : 2.412445,
"I2" : 2.607605,
"I3" : 2.655672
},
"Date" : "15-11-2019",
"Frequency" : 49.99259,
"Power Factors" : {
"Q1" : 0.997155,
"Q2" : 1,
"Q3" : 0.988455
},
"Powers" : {
"KA1" : 466.713,
"KA2" : 517.551,
"KA3" : 533.6165,
"KT1" : 465.3853,
"KT2" : 517.551,
"KT3" : 527.4558,
"KV1" : 35.17823,
"KV2" : 0,
"KV3" : 80.85116
},
"THDs" : {
"THDC1" : 64.92453,
"THDC2" : 59.34635,
"THDC3" : 54.73608,
"THDV1" : 1.798943,
"THDV2" : 2.569078,
"THDV3" : 1.955434
},
"Time" : "10-27-11am",
"Voltages" : {
"V1" : 231.1034,
"V12" : 400.4179,
"V2" : 231.2728,
"V23" : 400.3139,
"V3" : 230.767,
"V31" : 400.1738
}
}

And I need to retrieve the value of each individual field like I2, V23 etc and store them in a variable or an array. Can anyone help me out here ?

0 Kudos
Message 4 of 4
(3,563 Views)