LabVIEW Idea Exchange

About LabVIEW Idea Exchange

Have a LabVIEW Idea?

  1. Browse by label or search in the LabVIEW Idea Exchange to see if your idea has previously been submitted. If your idea exists be sure to vote for the idea by giving it kudos to indicate your approval!
  2. If your idea has not been submitted click Post New Idea to submit a product idea to the LabVIEW Idea Exchange. Be sure to submit a separate post for each idea.
  3. Watch as the community gives your idea kudos and adds their input.
  4. As NI R&D considers the idea, they will change the idea status.
  5. Give kudos to other ideas that you would like to see in a future version of LabVIEW!
Top Authors
cancel
Showing results for 
Search instead for 
Did you mean: 

Allow enums in "flatten to json"/"unflatten from json"

Status: New

Currently enums can not be in a cluster that you want convert to JSON. It would be great, if this could be added.

 

Either the enum value could be converted to its internal representation (e.g. u16) or the value could be saved as a string (make it easier to read the JSON and parse it outside LabVIEW).

 

The unflatten should be able to handle the u16 easily to convert back to enum or take the string and search through the enum of the datatype that one has to connect to the vi. If there is no match the VI can issue an error.

 

4 Comments
Member

I just ran into this issue myself. It makes it difficult to introduce JSON serialization into any existing code that includes enums in clusters.

 

The unflatten/flatten JSON VIs could just include an input terminal that allows you to specify whether you want enums to be encoded as their integer value or their string.

Proven Zealot

The JSON prim developers shied away from anything that wasn't specifically JSON; they assume that you'll translate your block of data into the data you want serialized. The primitives could have an options switch for "integers or strings" for enums. Or they could have just picked a behavior for enums. Both options have downsides, but both are significantly less work and significantly less memory usage than the current solutions.

 

Personally, I'd support just picking the string names.

 

(I would go further and say that the JSON prims should have a defined behavior for all LV data types, like the XML prims.... it might not be what you want, in which case you'd have to manage your own data translation, but it would be a fair sight more helpful in many cases than what we have now.)

Active Participant

letting ppl have the option to either have the selected number or the string (with defaulting to string) would be my preference.

 

i use the to-json serialization (or would like to) for my logging

 

the xml just spams all info, which makes it unusable for me ther

(especially if you have many cases in the enum)

 

regards


If Tetris has taught me anything, it's errors pile up and accomplishments disappear.
Active Participant

JKI JSON library allows flattening and unflattening enums to both numbers and strings.

 

jki.net/tools#json

--
Tomi Maila