Jump to content

[CR] JSON LabVIEW


Recommended Posts

  • Replies 240
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Popular Posts

The easiest way by far is to use the [un]Flatten to XML primitives, which can take objects and variants as arguments, and convert the XML to/from JSON. with simple regex/search/replace. Why they didn'

View File JSON LabVIEW JSON is a data interchange format (sometimes compared to XML, but simpler). There are multiple projects to create a JSON package for LabVIEW. T

I tried to use this tool. And it looks great, however the function 'Variant to JSON' fails with a variant inside an object. I made the following changes: -Added support for Variant. By using 'Unwrap

Posted Images

Looks good to me.  Any other changes before I make a new VIPM package?

 

One thing that I haven't gotten round to yet. If you re operating on a large JSON stream, you cannot process any other JSON streams as it seems to beblocking. I think it just needs setting some of the subVIs to re-entrant, but like I said. I haven't gotten round to looking as yet.

Link to post

Hello. For 2D Array of strings the VI: "Variant Decode" doesn't if the strings have different Sizes

 

I made some changes using the data string information : nnnnstrstrstr... (4 bytes with string size + the string itself). 

 
JSON 2D Array of Strings
Album: Code Examples
1 images
0 comments

 

 
Regards from Portugal.
Manuel Carvalho
 
Edited by mcarvalho
Link to post

Hi Manual,

 

thanks for the report, the last commit by James should be fixing this.

Shaun, I haven't seen this, by using a quite large JSON set, and parsing it twice in parallel, both methods can the same time.

 

Regards,

 

Ton

Link to post

Hi guys

 

Thumbs up for the good work!

 

I am creating a generic variant based intra-process configuration handler, and are considering using this as one of the user-selectable underlying 'file abstraction layers'.

However - since I plan on using an intermediate variant collection between the user and the file layer, I will need to be able to set new values in the JSON value tree without overwriting all other values.

Currently I don't see any way of doing this (I don't see a "Set sub-Item by names" function)..

 

Is this left out deliberately, or have you guys just not gotten around to it yet?! (or am I missing a point as to why it isn't implemented?) :)

Link to post

Hi again

 

Regarding the post above I took the liberty of adding the functionality to the project.

I have attached a zip file containing only the VI's I have added or changed (folder structure has been kept) - feel free to add it to the project if you want..

 

Changes:

 + Added VI's for updating an existing JSON Collection Object value - by Array of names

 + Added VI's for removing a JSON Collection Object - by Array of names

 * Changed polymorphic Set VI to include new features .. the 'Set Object' function has been made into a submenu..

 

Best Regards

Stinus

Changes to tcplomp-json-api-labview-0c0d17447fc4.zip

  • Like 1
Link to post
Hi Manual,

 

thanks for the report, the last commit by James should be fixing this.

Shaun, I haven't seen this, by using a quite large JSON set, and parsing it twice in parallel, both methods can the same time.

 

Regards,

 

Ton

 

It seems to be blocking with arrays.

 

Here's an example to demonstrate. The text file is made up of giant arrays so it makes it much more obvious (takes about .4 mins to execute)

 

I'll take a closer look on Sunday. A bit strapped for time at the moment.

Hi again

 

Regarding the post above I took the liberty of adding the functionality to the project.

I have attached a zip file containing only the VI's I have added or changed (folder structure has been kept) - feel free to add it to the project if you want..

 

Changes:

 + Added VI's for updating an existing JSON Collection Object value - by Array of names

 + Added VI's for removing a JSON Collection Object - by Array of names

 * Changed polymorphic Set VI to include new features .. the 'Set Object' function has been made into a submenu..

 

Best Regards

Stinus

 

Sweet.

I'll take a gander later.

Link to post
I’m about to go on holiday for two weeks, so I’m going to post a CR version with just the bug fixes made by James McNally, leaving other issues for later.

Why not just wait until you come back when the others will have been addressed too?

Link to post

I went over the code by Stinus, and it looks good and valid.

 

One of the open points in the code is retrieving attributes of waveforms. My proposal is to return each attribute as it's raw JSON string (indicated by a .JSON extension):

post-2399-0-39922200-1374326883.png

Any other ideas?

 

Ton

 

Link to post
Hi Manual,

 

thanks for the report, the last commit by James should be fixing this.

Shaun, I haven't seen this, by using a quite large JSON set, and parsing it twice in parallel, both methods can the same time.

 

Regards,

 

Ton

"Set From JSON String.vi", "Name.vi" and "First Char.vi" are not set to re-entrant.

Just downloaded the latest version and "Set From JSON String.vi" now seems to be reentrant which cures the blocking. The others are still not re-entrant though.

Link to post
  • 4 months later...
  • 1 month later...

Added Path case to "Variant To JSON.vi" and updated example.

(See this post)

 

Variant To JSON.vi

Example JSON Variant Tools.vi

 

I think the default case would be able to handle paths if Variant to JSON used OpenG Format Variant Into String.  Why was this not done?

Because the intention is (was?) to remove OpenG dependencies completely...

Link to post

Thanks for the fix!  I wish I had found this thread earlier.  Can anybody create a new build and check it into bit bucket or is that reserved for people on the team?  Can somebody get the fix into a new build?



One thing that I haven't gotten round to yet. If you re operating on a large JSON stream, you cannot process any other JSON streams as it seems to beblocking. I think it just needs setting some of the subVIs to re-entrant, but like I said. I haven't gotten round to looking as yet.

 

 

I have seen similar behavior.  I can try to replicate it if anybody is interested. What I found was that if GetTypeInfo is being called by two separate application instances they block each other because it's non-reentrant.  I don't think we are going to find a work around for that.  This might be a unique situation that I found because of the multiple application instances aspect but I figured it was worth mentioning.

Link to post
Thanks for the fix!  I wish I had found this thread earlier.  Can anybody create a new build and check it into bit bucket or is that reserved for people on the team?  Can somebody get the fix into a new build?

 

 

I have seen similar behavior.  I can try to replicate it if anybody is interested. What I found was that if GetTypeInfo is being called by two separate application instances they block each other because it's non-reentrant.  I don't think we are going to find a work around for that.  This might be a unique situation that I found because of the multiple application instances aspect but I figured it was worth mentioning.

The fix has already been pushed to bitbucket. The others will review it then, if it's acceptable, drjdpowell will fold in any other changes and build a VIP package for the CR (only he can update the CR).

Link to post
  • 2 weeks later...

After doing some testing I found that JSON to Variant can't handle empty paths.  The problem is caused by the OpenG Scan Variant From String throwing error #1 because the string it is scanning is empty.  A simple fix would be to add an additional case structure to handle paths within JSON to Variant.  

Link to post
After doing some testing I found that JSON to Variant can't handle empty paths.  The problem is caused by the OpenG Scan Variant From String throwing error #1 because the string it is scanning is empty.  A simple fix would be to add an additional case structure to handle paths within JSON to Variant.  

 

I think the OpenG Scan Variant From String is obsolete since JSON to Variant can handle all types now (apart from refnum and path-which are easily added). We should consider removing the OpenG Scan Variant From String completely. I would also suggest that for the unknown data type we output a string type and raise a warning  rather than an error..

Edited by ShaunR
Link to post

I think the OpenG Scan Variant From String is obsolete since JSON to Variant can handle all types now (apart from refnum and path-which are easily added). We should consider removing the OpenG Scan Variant From String completely. I would also suggest that for the unknown data type we output a string type and raise a warning  rather than an error..

 

Sounds good to me.  I am new to BitBucket so excuse me if this sounds stupid but do I have to be part of the "Team" to download the source?  I have SourceTree installed but I think I am blocked from contributing.  

 

If I had access I would be glad to make these changes.

Link to post

I just committed my code to BitBucket for handling paths and refnums.  Should the commit be showing up in BitBucket before it's reviewed?  This is my first BitBucket project and I am trying to make sure that I didn't screw up and step on anybodies toes.  Let me know...

Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Similar Content

    • By drjdpowell
      View File JSONtext
      Package for working with JSON.  Uses high-speed text parsing, rather than building an intermediate representation as with prior LabVIEW JSON libraries (this is much faster).  Allows easy working with "subitems" in JSON format, or one can convert to/from LabVIEW types.  Uses the new "malleable VIs" of LabVIEW 2017 to convert to any LabVIEW type directly.
      JSON text makes use of a form a JSON Path notation, allowing easy and rapid access to the subitems of interest.
      Requires LabVIEW 2017 and install by VIPM 2017 or later.
      Original conversation about JSONtext.
      On the LabVIEW Tools Network.
      JDP Science Tools group on NI.com.
      Copyright 2017 JDP Science Limited
      Submitter drjdpowell Submitted 08/02/2017 Category General LabVIEW Version 2017 License Type BSD (Most common)  
    • By drjdpowell
      Package for working with JSON.  Uses high-speed text parsing, rather than building an intermediate representation as with prior LabVIEW JSON libraries (this is much faster).  Allows easy working with "subitems" in JSON format, or one can convert to/from LabVIEW types.  Uses the new "malleable VIs" of LabVIEW 2017 to convert to any LabVIEW type directly.
      JSON text makes use of a form a JSON Path notation, allowing easy and rapid access to the subitems of interest.
      Requires LabVIEW 2017 and install by VIPM 2017 or later.
      Original conversation about JSONtext.
      On the LabVIEW Tools Network.
      JDP Science Tools group on NI.com.
      Copyright 2017 JDP Science Limited
    • By ThomasGutzler
      Hi,
      I'm receiving a JSON string from a web API, which I'm trying to convert into a cluster (of clusters) but I've run into some problems:
      1) Sometimes the order of the elements in the JSON string changes, which causes my conversion to fail.
      2) Sometimes the "object" returned via JSON is null, which causes my conversion to fail if I use clusters within clusters. It works with variants in clusters but then I need to convert the all the variants manually
      Is there any way to improve my code to fix those problems? The attached snippet is a simplified version. In my project, the first JSON string to data is done in a library. The second conversion from "result" variant to data is done in my application. This makes a direct conversion from JSON string more difficult.

    • By drjdpowell
      JSON is a data interchange format (sometimes compared to XML, but simpler). There are multiple projects to create a JSON package for LabVIEW. This is yet another one motivated by this hijacked conversation originally about a different project to convert JSON into LabVIEW Variants.

      This project uses a set of LVOOP classes to match the recursive structure of JSON, rather than variants. It allows conversation to and from JSON. All functionality is available through two polymorphic VIs: Set and Get. In addition to Get and Set VIs for common data types, one can also convert directly to or from complex clusters via variant-JSON tools.

      Copyright 2012-2016 James David Powell, Shaun Rumbell, Ton Plomp and James McNally.
      [Note: if you are using LabVIEW 2017, please also see the JSONtext library as a an alternative.]
    • By Pavanb
      Hi There 
      I want to go from TestStand's output i.e. database to HTML5 SPC charts. Sorta like http://moderndata.plot.ly/using-plotly-from-labview-via-python/ Has anyone done this or used Bokeh or Enthough's data tool before?  What about these tools with TDMS or HDF5?
      Thanks. I appreciate it.
      Best,
      Pavan 
      By the way, https://www.enthought.com/services/consulting/case-studies/TAIPAN/ (like TestStand without TestStand)
       



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.