08-24-2016 10:45 AM - edited 08-24-2016 11:04 AM
Hi all,
I tried to parse the JSON here under coming from thirdy part web service.
I was able to parse only the inner part using NI "unflatten from JSON". The main problem are:
1) this JSON is an array of different type objects
2) this JSON contain value without name
Every advice will be helpfull and thanks in advance
Golzio
[{
"name": "DC Comics",
"rev": [
[1389826800000, {
"Note": "Note Title 1",
"Vote": "EVEN",
"createdBy": "Batman",
"timeInMills": 1389826800000,
"detailNote": "This a detailed note"
}],
[1391122800000, {
"Note": "Note Title 2",
"Vote": "EVEN",
"createdBy": "Superman",
"timeInMills": 1391122800000,
"detailNote": "This a detailed note"
}],
[1392418800000, {
"Note": "Note Title 3",
"Vote": "EVEN",
"createdBy": "Wonderwoman",
"timeInMills": 1392418800000,
"detailNote": "This a detailed note"
}]
]
}, {
"name": "Marvel",
"rev": [
[1388530800000, {
"Note": "Note Title 3",
"Vote": "EVEN",
"createdBy": "Spiderman",
"timeInMills": 1388530800000,
"detailNote": "This a detailed note"
}]
]
}]
Solved! Go to Solution.
08-24-2016 11:03 AM
The valid json to be unflattened is the following:
[{
"name": "DC Comics",
"rev": [
[1389826800000, {
"Note": "Note Title 1",
"Vote": "EVEN",
"createdBy": "Batman",
"timeInMills": 1389826800000,
"detailNote": "This a detailed note"
}],
[1391122800000, {
"Note": "Note Title 2",
"Vote": "EVEN",
"createdBy": "Superman",
"timeInMills": 1391122800000,
"detailNote": "This a detailed note"
}],
[1392418800000, {
"Note": "Note Title 3",
"Vote": "EVEN",
"createdBy": "Wonderwoman",
"timeInMills": 1392418800000,
"detailNote": "This a detailed note"
}]
]
}, {
"name": "Marvel",
"rev": [
[1388530800000, {
"Note": "Note Title 3",
"Vote": "EVEN",
"createdBy": "Spiderman",
"timeInMills": 1388530800000,
"detailNote": "This a detailed note"
}]
]
}]
08-24-2016 12:19 PM
I was able to parse it using the "JSON toolkit for LabVIEW":
Attached a sample VI.
If someone has good advice to parse using native NI vi please let me know.
Regards
Golzio
08-24-2016 12:39 PM
Hey Golzio,
The problem here is that the Unflatten from JSON primitive only makes it easy to parse JSON data that be well represented by LabVIEW's types. So cases like this where we have an array with mixed types are more difficult.
It is possible to parse JSON Arrays with mixed types using LabVIEW's primitives. This is done by using the path input on Unflatten from JSON to navigate into the JSON data and extract the values you need.
The following example shows how you can create paths to extract the data from your data set:
From that example you can see how we build the path array in loops and use Unflatten From JSON to extract values one-by-one. A problem with this approach is that we are calling the Unflatten from JSON many times inside a loop so this might not scale well for large data sets with thousands of items. The benefit is not requiring external dependencies.
I'm glad the i3 JSON toolkit worked for you (full disclosure I developed that specific toolkit) and it's good to know that there are other options are available such as the newer JKI JSON Toolkit and the existing LAVA JSON LabVIEW Toolkit
08-25-2016 02:20 AM
Hi Milan,
thank you very much for your time.
It was very useful to understand better and in deep the smart use of "path" input of "Unflatten form JSON".
Golzio
08-02-2017 04:01 PM - edited 08-02-2017 04:03 PM
I've just released a new library called JSONtext. Part of the reason for a new library is to provide more complete support of JSON, including mixed-type arrays. Here is a solution to the above problem, using JSONtext:
In JSONtext, mixed-type JSON arrays can be unflattened to clusters of unnamed elements.
02-20-2018 02:55 AM
Hello drjdpowell,
I'm a student, and a begener on labview.
In my internship I receive data from a server in JSON and my job it's to recover this data and make some graphics in Labview.
So i was very happy to find your new library JSONtext so I have download it.
The problem is when I want to Use for exemple the VI From JSON text, labview start to download some files and after he ask me to open two VI:
- Array of Variants to Cluster.vi
- Trim Whitespace_JDP.vi
But I can't find this 2 VI....
Can you please helped me.
I have labview 2017
My JSON file look like this:
[
{ "measurement": "ACPowerFromStorage", "value": { "dataGeohash": "u0p70yfrzmu1", "last": 0, "time": "2018-02-20T08:48:39Z" } }, { "measurement": "ACPowerToStorage", "value": { "dataGeohash": "u0p70yfrzmu1", "last": 990, "time": "2018-02-20T08:48:39Z" } }, { "measurement": "AmbientTemp", "value": { "dataGeohash": "u0p70yfrzmu1", "last": 0, "time": "2018-02-20T08:48:39Z" } },
02-20-2018 03:50 AM
I found the problem I forgot to download the package: jdp_science_lib_common_utilities
Problem solved