01-25-2018 04:47 AM
Hi,
I'm using the i3 json toolkit for LabVIEW : https://forums.ni.com/t5/JSON-Toolkit-for-LabVIEW/gp-p/8520?start=0&view=discussions
I'm facing an error when using the json below and trying to get the "cmd" value :
{"cmd":{"module":"test1","name":"Session"}}
Get Object parameter VI returns :
Variant To Data in i3-json.lvlib:Get Object Parameter - String.vi->RS_GetJsonElement.vi
This case seems basic so I might be mistaking somehow.
Does any one get the same issue using this library, and is there a way to fix it?
Thanks in advance for your support,
Bim
01-25-2018 04:58 AM
Attached vi snapshot
01-25-2018 01:47 PM
Hi Bim,
In the example JSON provided it can be thought of as follows:
A JSON object with one parameter. That parameter is named cmd.
The cmd parameter is a JSON object with two parameters. The parameters are module and name.
The module parameter is a string with value "test1".
The name parameter is a string with value "Session".
In the VI screenshot the parameter cmd was read as a String which returned an error because the cmd parameter is a JSON object. To extract the cmd parameter you have to read it as a JSON object. To then read module and name parameters you have to look them up from the cmd JSON object:
01-25-2018 01:55 PM
If you are using LabVIEW 2013 or greater you may also consider using the Unflatten From JSON primitive built into LabVIEW instead:
Unflatten from JSON generally gives better performance and can be easier to use in many cases.
01-25-2018 05:02 PM
Hi Milan,
Many thanks for your feedbacks. Actually I was expecting it to manage both cases and result a string that could be the flattened json as string.
I'll build for the moment a specific vi for my basic need as this dependency on the input json form is blocker.
Thanks,
BR,
Bim
01-25-2018 08:02 PM
You can use the Encode JSON vi to serialize a JSON Object back into a string encoded as JSON. The following shows how the cmd parameter is retrieved and serialized into a JSON string.
01-30-2018 03:28 AM
Hi Milan,
Great example, I was missing something and now it's clear.
Many thanks for your support!
Bim