LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Limit significant figures in JSON String

Solved!
Go to solution

Hello,

 

I have a LV application that makes intensive use of JSON to transmit real time data to http clients. I'm trying to reduce the data bandwith consumption and improve the user experience on poor networks limiting the number of decimals of the JSON arrays of numbers. Because the clients only use 4 significant figures, and the rest of decimals are useless traffic.

 

I have developed a VI that does the job. The problem is that if I make the output of this VI to be a string, then when I parse to JSON I will have an array of strings instead of numbers. And if I change the output to DBL, then things like this happens:

 

DBL: 1234,1; JSON String: [1234.0999999999999091].

 

So... I don't see a clear way to do this. And it would be highly preferable to not have to change the clients' code...

 

I look forward your ideas. Best regards,

 

 

EMCCi

0 Kudos
Message 1 of 3
(2,661 Views)
Solution
Accepted by topic author EMCCi

The in-built LabVIEW functions are very verbose, but you can use JSONtext (on Tools Network) instead, which is designed to represent decimal numbers exactly.  This will flatten 1234,1 to 1234.1.

Message 2 of 3
(2,634 Views)
Solution
Accepted by topic author EMCCi

Thanks for your response. Didn't know about these tools.

 

Anyway, while waiting for an answer I was working on my solution. It only work for arrays, but it could be easily modified to work also with clusters. I upload it just in case it could be useful for someone.

 

Thanks and regards,

 

 

EMCCi

Message 3 of 3
(2,617 Views)