LabVIEW Idea Exchange

cancel
Showing results for 
Search instead for 
Did you mean: 
matt.baker

Flatten to JSON - Allow any data type on the "anything" input

Suggestion: Allow any data type to be connected to the "anything" terminal of the flatten to JSON function.

Basically the same as the flatten to XML function.

 

Also the reverse, unflatten from JSON, may need to be done as well.

 

Flatten to JSON.png



Using LV2018 32 bit

Highly recommended open source screen capture software (useful for bug reports).

https://getsharex.com/
39 Comments
Tomi_Maila
Active Participant

Darren,

 

Thanks for the update. I don't see this anymore as a major issue becasue there are third party tools that can provide the support missing from LabVIEW. I maintain one of those tools, the JKI JSON library, which supports many more data types than LabVIEW does. If anyone has suggestions to what is missing from the support, please submit an issue report the JKI JSON GitHub page.

 

Tomi

--
Tomi Maila
drjdpowell
Trusted Enthusiast

>>I don't see this anymore as a major issue becasue there are third party tools that can provide the support missing from LabVIEW.

 

The problem is speed, Tomi.  Existing JSON addons like JKI's or LAVA's are orders of magnitude slower than the inbuilt primative.  This restricts their use to applications where speed doesn't matter (config files, for example).   

Tomi_Maila
Active Participant

djrdpowell,

 

That's true. The LabVIEW reflection API is way too slow for the third party solutions to be able to match with the native performance. The preferred solution to the problem would be for NI to make the reflection API orders of magnitude faster. That would help not only to this problem but a lot of other problems. Right now flattening to JSON can be relatively fast using the third party libraries, unflattening from JSON is quite slow compared to the built-in JSON.

 

Tomi

--
Tomi Maila
AristosQueue (NI)
NI Employee (retired)

Don't use a reflection API. Write a JSON serialization for your data type, and if you don't want to hand-code it, use scripting to generate it -- or regenerate it when it changes. Regeneration is generally the harder challenge anyway with non-primitive data structures. You quickly start needing version management control, nesting of data structures with independent change schedules, etc. It happens to pretty much every piece of software I've ever worked on that had any sort of serialization component, down to the smallest utility apps. The reflection API approach rarely helps with that.

 

This is the approach taken by the Character Lineator. I think it is overall a better way to go for any information that will be needed for more than just temporary string transfers.

drjdpowell
Trusted Enthusiast

 > use scripting to generate it -- or regenerate it when it changes

 

Do you mean xnodes or similar here?  That may be a good solution for flattening clusters/objects, but I definately have code use cases where there is no statically-defined data type structure to (re)generate from.  For example, I have code that performs statistics on supplied JSON data, and applies User specified test conditions, without knowing at compile time the structure of the data.

AristosQueue (NI)
NI Employee (retired)

JDPowell: That's outside the use case of Flatten To JSON and Unflatten From JSON functions anyway. You want a DOM parser for JSON. This thread was discussing the Flatten and Unflatten nodes.

drjdpowell
Trusted Enthusiast

 OK, but isn't the current NI JSON functions too inflexible to be used for many flattening operations?  In anything that requires a combined JSON structure coming from multiple sources (a config file for a multi-module project, say, or a JSON flat form of an object where multiple classes contribute) the current primatives are unusable.

PBD_ctrl
Member

NI wants to play in the IOT but can't natively support JSON without using external tools or developing your own.  Doesn't line up to me.

drjdpowell
Trusted Enthusiast

PBD_ctrl, FYI,

I've got a side project for a new JSON library, "JSONtext", that I hope to be much closer in performance to the inbuilt primatives, while being highly flexible:

 

https://lavag.org/topic/19830-what-do-you-use-json-for/?do=findComment&comment=120103

Tomi_Maila
Active Participant

--
Tomi Maila