11-05-2019 11:36 PM
Is it possible to pass objects, say via JSON, into Labview and vice versa? Now I realize there's likely not a way to enforce or be aware of class heirarchy and such between two languages, and that probably one would have to ensure the class/objects are equivalent on both sides of the "language barrier" - but is it possible if one setup an identical structure in another language, that an object, in JSON, could be instantiated in labview at runtime?
11-06-2019 02:58 AM
Hi DrAutomatic,
what is your use case for exchanging objects between different executables?
Would it be easier (and maybe more senseful) to exchange just data?
@DoctorAutomatic wrote:
one would have to ensure the class/objects are equivalent on both sides of the "language barrier" - but is it possible if one setup an identical structure in another language, that an object, in JSON, could be instantiated in labview at runtime?
Do you really think you can setup the very same internal structure used to store objects in LabVIEW with a different programming environment?
11-06-2019 04:34 AM
You can Flatten to JSON\XML. And you can send it. Whether the other side can use it, isn't really a LabVIEW question, but most languages can parse XML\JSON or at least strings.
Note that Flatten to JSON\XML is tricky. There is a 'feature', that removes all objects of a cluster\class from the JSON\XML if\when the cluster\class is default. So in stead of sending a string with data of the object's values, you get crap.
You need to handle that in either LV or the other side.
@DoctorAutomatic wrote:
is it possible if one setup an identical structure in another language, that an object, in JSON, could be instantiated in labview at runtime?
So that's a yes, I guess.
Python for instance will gladly receive a JSON string, and convert it to an object. It doesn't really care about it's content...
11-06-2019 08:37 AM
wiebe@CARYA wrote:
Python for instance will gladly receive a JSON string, and convert it to an object. It doesn't really care about it's content...
But it can't do much with such an object! The contents is just a binary stream that has no functional meaning to Python.
11-06-2019 08:50 AM - edited 11-06-2019 08:52 AM
@rolfk wrote:
wiebe@CARYA wrote:
Python for instance will gladly receive a JSON string, and convert it to an object. It doesn't really care about it's content...
But it can't do much with such an object! The contents is just a binary stream that has no functional meaning to Python.
A JSON string or XML string isn't binary?
I got JSON strings from REST, and Python can work with it just fine.
Obviously a Flattened to JSON LV class it's not a class object in Python, until you set the data to the Python class. But there's no reason you can't make that work.
11-06-2019 08:54 AM
Well if you don't convert the JSON then yes, it is a string basically. But you still can't do to much with it. A string object in Python has a number of specific methods and properties and that's mostly it. To convert it into a Python object with similar functionality as the LabVIEW object you would need to reprogram the object in Python and add a Serialize/Deserialize method from a LabVIEW JSON String. Very possible but also very cumbersome especially if you want to do more than one or two object classes.
11-06-2019 09:37 AM
@rolfk wrote:
Well if you don't convert the JSON then yes, it is a string basically. But you still can't do to much with it. A string object in Python has a number of specific methods and properties and that's mostly it. To convert it into a Python object with similar functionality as the LabVIEW object you would need to reprogram the object in Python and add a Serialize/Deserialize method from a LabVIEW JSON String. Very possible but also very cumbersome especially if you want to do more than one or two object classes.
The de-serializing of JSON in Python is easy. But that converts the JSON to a Python object.
Passing an object (data and functionality) is simply not possible. Passing data is very well possible.
I agree, converting the LabVIEW object to a Python object with the same functionality will only be practical for a few objects.
Not sure what OP wants with the 'objects'?
>Possible to pass objects between LV and other languages?
Possible, sure. Practical, maybe.