LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Unflatten JSON string skipped out non printable characters

 

I would like to have any kind of data (binary data to be exact) flattened to JSON and back to the original data. When tested out the stock JSON utility and also the JKI variant, both utilities skipped out non printable characters silently (no error was given).


My test data was escaped correctly as in:

{
"test":"\u0000\u0001\u0013"
}

 

Can anyone tell me if this is expected behavior or how do I get the original data stay put before and after flattening. I believe this is also the same concept for "ini" or "xml" methods.

Thanks !

Clipboard_20170621.jpg

Clipboard_20170621 (2).jpg

0 Kudos
Message 1 of 12
(4,250 Views)

Hmmm...

I don't have an answer but maybe the workaround is to use the regular flatten to string and unflatten from string?

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 2 of 12
(4,206 Views)

Hi, I spotted that out that the flatten/unflatten from string utilities can work with binary data. But however this format is specific to LV and it is unknown I would foolproof a matching conversion method in other language like C# for example. I would like to look for common format like JSON if possible. By the way, character 0x13 is CR which is printable, how come it got skipped out too in the conversion result ?

0 Kudos
Message 3 of 12
(4,201 Views)

The inbuilt JSON primitives have bug in them that they truncate strings on the first \u0000 character.  Don’t know about the JKI library.   You could also try the LAVA one.  I helped write that one, and it should handle those characters.

Message 4 of 12
(4,197 Views)

Im facing the same problem. Does anyone know whether this is a bug? Or caused by JSON standard?

Certified LabVIEW Developer
There are only two ways to tell somebody thanks: Kudos and Marked Solutions

GCentral
0 Kudos
Message 5 of 12
(3,477 Views)

@Tepig wrote:

Im facing the same problem. Does anyone know whether this is a bug? Or caused by JSON standard?


The \u0000 thing is a bug, CAR 605085.

 

Try JSONtext, which doesn't have this issue.

Message 6 of 12
(3,467 Views)

Another alternative is to Base64 Encode binary data to add to your JSON message and Base64 Decode the binary data after parsing the JSON. Using Base64 encoding is a common way to safely represent arbitrary binary data as strings.


Milan
Message 7 of 12
(3,460 Views)

Hi drjdpowell

 

I really appreciate your suggestion. I will try it out!

Certified LabVIEW Developer
There are only two ways to tell somebody thanks: Kudos and Marked Solutions

GCentral
0 Kudos
Message 8 of 12
(3,438 Views)

To tell the truth, I haven't used Base64 encode so, may take a lot of time to implement the feature.

But it is a common way, isn't it? I will learn the method. Thanks!

Certified LabVIEW Developer
There are only two ways to tell somebody thanks: Kudos and Marked Solutions

GCentral
0 Kudos
Message 9 of 12
(3,436 Views)

Finally, I decided to implement Base64.

JsonText looked good but didn't work perfectly. Some parameters weren't converted...

 

I found good example code here.

LabVIEW Utility VIs for Base64 and Base32Hex Encoding Using LabVIEW

And this code worked perfectly.

 

Thanks all : D

 

 

Json_binary_encoding.png

 

Certified LabVIEW Developer
There are only two ways to tell somebody thanks: Kudos and Marked Solutions

GCentral
0 Kudos
Message 10 of 12
(3,431 Views)