06-21-2017 03:43 AM - edited 06-21-2017 03:52 AM
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 !
06-21-2017 09:27 AM
Hmmm...
I don't have an answer but maybe the workaround is to use the regular flatten to string and unflatten from string?
06-21-2017 11:37 AM
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 ?
06-21-2017 11:50 AM
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.
03-29-2019 03:38 AM
03-29-2019 07:58 AM
03-29-2019 11:01 AM
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.
03-31-2019 06:51 PM
03-31-2019 06:54 PM
03-31-2019 09:06 PM
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