LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I make a string recieved from a JSON command modular?

Solved!
Go to solution

Hello Everyone,

For my part-time vacation work, I need to read a Janitza Power Analyser.
At the moment I do this by using a JSON URL:

http://10.0.0.6/json.do?_ULL[0],_ULL[1],_ULL[2],_ILN[0],_ILN[1],_ILN[2],_P_SUM3,_Q_SUM3,_COS_SUM3,_EXT_TEMPERATUR,_FFT_UL1[0..40],_FFT_UL2[0..40],_FFT_UL3[0..40],_FFT_UL4[0..40]

It is just a URL that will retrieve a lot of data I need for my project

This URL will retrieve this JSON text:

{ "_ULL": [[ 
233.6660],"V"], "_ULL": [[ 
404.3061],"V"], "_ULL": [[ 
233.4296],"V"], "_ILN": [[ 
0.0031],"A"], "_ILN": [[ 
0.0027],"A"], "_ILN": [[ 
0.0021],"A"], "_P_SUM3": [0.7253,"W"], "_Q_SUM3": [0.4137,"var"], "_COS_SUM3": [0.8687,""], "_EXT_TEMPERATUR": [26.3345,"�C"], "_FFT_UL1": [[ 
78.2524,
0.1335,
0.4667,
0.0995,
1.8770,
0.0890,
1.4509,
0.0771,
0.8035,
0.0771,
0.6262,
0.0445,
0.4127,
0.0771,
0.6069,
0.0771,
0.2355,
0.0445,
0.2312,
0.0771,
0.5819,
0.0445,
0.2633,
0.0445,
0.1090,
0.0629,
0.1476,
0.0000,
0.0890,
0.0771,
0.0629,
0.0771,
0.0629,
0.0629,
0.0771,
0.0445,
0.0629,
0.0445,
0.0445,
0.0629],"V"], "_FFT_UL2": [[ 
205.8328,
0.1542,
0.3300,
0.0995,
4.4774,
0.0771,
3.7072,
0.0771,
0.2312,
0.0890,
1.2759,
0.0629,
1.2516,
0.0629,
0.1177,
0.0771,
0.2312,
0.0771,
1.2944,
0.0629,
0.1177,
0.1090,
0.4103,
0.0445,
0.3532,
0.0995,
0.1177,
0.0771,
0.1090,
0.0771,
0.0995,
0.0771,
0.0890,
0.0445,
0.0629,
0.0629,
0.1259,
0.0771,
0.0629,
0.0445],"V"], "_FFT_UL3": [[ 
205.9290,
0.1476,
0.1605,
0.1090,
4.4274,
0.0771,
3.7429,
0.0995,
0.5954,
0.0890,
1.3952,
0.0995,
1.3298,
0.0771,
0.5486,
0.0890,
0.4151,
0.0445,
1.2122,
0.0771,
0.6495,
0.0771,
0.5819,
0.0890,
0.3051,
0.0445,
0.1888,
0.0445,
0.1724,
0.0890,
0.1259,
0.0629,
0.0771,
0.0771,
0.0629,
0.0771,
0.0771,
0.0629,
0.0629,
0.0771],"V"], "_FFT_UL4": [[ 
30.0330,
0.2134,
13.4254,
0.2134,
2.9056,
0.1542,
2.4645,
0.0890,
0.6822,
0.0995,
0.4494,
0.0771,
0.5836,
0.0629,
0.2312,
0.0995,
0.1888,
0.0000,
0.2396,
0.0890,
0.1476,
0.0445,
0.1665,
0.0445,
0.2087,
0.0890,
0.1888,
0.0445,
0.2355,
0.0629,
0.1177,
0.0445,
0.0890,
0.0771,
0.0445,
0.0629,
0.0995,
0.0445,
0.0629,
0.0000],"V"]}


At the moment I get this as a string, I will edit this string to get all the data I need in a cluster.
As you can see in my attached VI this is pretty labor-intensive and since they want to use this in more project. I need to make it modular, wich basicly means: 
A input will be the URL, and the program will edit this in a nice cluster.

Now I have tested some examples were they try to unflatten this string. To bad all the clusters the examples make, have lost some data or made clusters that are not really for use.

 

Can someone help me with tackling this?
I have only one solution at the moment, and that will be making a JSON URL with -+ 1000vars and put them all in a cluster by myself like the attached VI. 

0 Kudos
Message 1 of 9
(4,595 Views)

Use the Flatten/Unflatten from JSON VIs that started shipping with LabVIEW 2013?

 

Just like the flatten/unflatten from string - it will convert a cluster to a JSON string and vice-versa. You just have to make your LabVIEW cluster match the format of the JSON string:

 

json_convert.png

 

You can also access individual items by their path (e.g. element names, index).

 

If you're using an older version of LabVIEW - there might be a toolkit available.


LabVIEW Champion, CLA, CLED, CTD
(blog)
Message 2 of 9
(4,522 Views)

You have probably already seen this example but just in case you have not. https://decibel.ni.com/content/docs/DOC-35413. 




Joe.
"NOTHING IS EVER EASY"
Message 3 of 9
(4,499 Views)

@Joe_H wrote:

You have probably already seen this example but just in case you have not. https://decibel.ni.com/content/docs/DOC-35413. 


Your link is broken I believe this is what you meant to link to.

https://decibel.ni.com/content/docs/DOC-35413

Message 4 of 9
(4,464 Views)
Solution
Accepted by topic author Rickvb

What I've done: 
I spend half a day trying to make a code with the json unflatten/flatten VI's. 
I could not edit the example codes enough to get a code that automatically generates a cluster with the data in it. Without any dataloss and in the right format...

 

So after spending this much time, I thought it will take less time the make a URL with ALL the data in it (it was alot), and seperate the whole string piece by piece.
It did take me 1,5 days to get this to work. But now it seems like it works greatly. The programmer who wants to use this code now only has to unbundle the cluster and choose what he wants to read.
It takes about 300ms to run this VI which is fast enough.

Thank you all for the comments, I greatly appreciate the help!

0 Kudos
Message 5 of 9
(4,434 Views)

You may have been unable to get a JSON parser to work on that string because of the non-unique names (three "_ULL"s and three "_ILN"s).  If you could get _ULL and _ILN back as three-element arrays, rather than non-uniquly-named elements, then it should work.

Message 6 of 9
(4,391 Views)

Thankyou for your response. I did already try to change the URL and try to get it to work. But it seems I still get the same stuff: Data missing... Which is probably my own fault. The problem is, atm I got a real busy planning and since I already got a semi-solution, I will try this again over a few weeks 🙂 

0 Kudos
Message 7 of 9
(4,357 Views)

@drjdpowell wrote:

You may have been unable to get a JSON parser to work on that string because of the non-unique names (three "_ULL"s and three "_ILN"s).  If you could get _ULL and _ILN back as three-element arrays, rather than non-uniquly-named elements, then it should work.


To get around this problem - you can use the 'path' input to the JSON to Cluster and specify integers to get the elements by index rather than by name. That should solve the duplicate names issue.

 

I think the names should be unique in the JSON string - as everything tends to be based on named keys it doesn't sense to have duplicates otherwise you will find it difficult to refer to the items.


LabVIEW Champion, CLA, CLED, CTD
(blog)
0 Kudos
Message 8 of 9
(4,348 Views)

Something that might be helpful in the future is to validate strings like this using jsonlint. When I ran your code through it the only way to get it legal was to delete all the duplicate labels. I know you already got that answer, but it might have saved you some time.

 

Mike...


Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 9 of 9
(4,297 Views)