LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Decoding JSON

Solved!
Go to solution

@LeeBowers1 wrote:

Yea, the device manufacturer are telling me it has to be floating point. If i manually manipulate the resulting string from the function the device responds correctly. 

Not sure where to go from here now


Hmm. "22" can be a floating point, it just doesn't have any decimals.

 

Either manipulate the string, or use a library that does allow you to specify this. Perhaps someone can point one out.

 

For the manipulation, we can help if you tell us what to change. All numbers? Specific numbers? Numbers in arrays? Etc..

 

This adds ".0" to all integers labeled "a":

JSON Replace Integer.png

 

 

0 Kudos
Message 11 of 21
(1,166 Views)

I have attached my code.
If i send the string, at the bottom of case 2, the device works as it should. Else it sends 22 and the device doesnt respond. if i send 22.1, for example, i then get 22.11111115566 - it gives me loads of digits after the dp.
I appreciate your help on this matter, thank you

0 Kudos
Message 12 of 21
(1,161 Views)

your little snippet of code This adds ".0" to all integers labeled "a": would work but i tried to copy the function but it isnt working. do you have the actual vi please you can send.

Thank you

0 Kudos
Message 13 of 21
(1,157 Views)

If I set it to 22.1, I get ":22.100000000000001421". Both are right, 22.1 probably can't be represented as exactly 22.1, because of the limited resolution of the float...

 

Does the device accept these "long floats"? Or is it really picky? Must it be exactly 1 decimal?

 

I'm sure we can make a reg.ex. to fix this as well, if it's required.

0 Kudos
Message 14 of 21
(1,155 Views)

@LeeBowers1 wrote:

your little snippet of code This adds ".0" to all integers labeled "a": would work but i tried to copy the function but it isnt working. do you have the actual vi please you can send.

Thank you


The forum messes up those images, by shrinking the size. You can get a valid snippet from the link, but it's tricky.

0 Kudos
Message 15 of 21
(1,149 Views)

sorry forgot to mention, im on version 17

0 Kudos
Message 16 of 21
(1,146 Views)
Solution
Accepted by topic author LeeBowers1

Recreating it would probably have been faster (just remember to set the Search and Replace String to reg.ex.).

 

The snippet wouldn't work for LV17,even if you got a proper download.

0 Kudos
Message 17 of 21
(1,129 Views)

Recently, I've been using the JSONText add-on as it accepts a JSON path expression (with a few limitations in the current release) to extract individual/multiple items from the JSON text string, in addition to the previously discussed example of wiring a cluster to define the datatype for the entire JSON string.  It's available for LabVIEW 2017+ on the VI Package Manager.

 

Here's a link if you don't have the VI Package Manager.  http://sine.ni.com/nips/cds/view/p/lang/en/nid/216651

 

If you're unfamiliar with JSON paths, this online tool is quite helpful https://jsonpath.com/

0 Kudos
Message 18 of 21
(1,126 Views)

reg .ex - regular expression ........ found it WOW ok - working a treat - Thank you isn't enough but thank you.

0 Kudos
Message 19 of 21
(1,120 Views)

@pjroland1121 wrote:

Recently, I've been using the JSONText add-on as it accepts a JSON path expression (with a few limitations in the current release) to extract individual/multiple items from the JSON text string, in addition to the previously discussed example of wiring a cluster to define the datatype for the entire JSON string.  It's available for LabVIEW 2017+ on the VI Package Manager.


 

Big question is if it allows you to specify the nr. of decimal points...

0 Kudos
Message 20 of 21
(1,118 Views)