Jump to content

Recommended Posts

51 minutes ago, RogerSaele said:

There is no support for fixed-point numbers.

there is hardly support in labview itself ;)

In reality this is a pretty easy fix to do on your own branch of the code. Inside here:

https://bitbucket.org/drjdpowell/jsontext/src/default/Variant to JSON Text.vi

and here: https://bitbucket.org/drjdpowell/jsontext/src/default/JSON text to Variant.vi

If you look for every case structure using the type enum, find the case for "extended precision" and then add "Fixed Point" to the same case. Numeric variants automatically coerce so it should work as simple as that. (I suggest extended because of the different variations of fixed point, potentially using 64 bits in a more efficient manner than say a 64 bit double. You will still possibly lose precision)

Edited by smithd
Link to post
Share on other sites
  • Replies 110
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Popular Posts

View File JSONtext Package for working with JSON.  Uses high-speed text parsing, rather than building an intermediate representation as with prior LabVIEW JSON librari

working on it

Definitely on my list of JSONtext additions.  Ideally, I would want to implement RFC 7396: JSON Merge Patch, with the ability to generate a "patch" of the differences between two JSON texts, then appl

Posted Images

1 hour ago, smithd said:

there is hardly support in labview itself ;)

In reality this is a pretty easy fix to do on your own branch of the code. Inside here:

https://bitbucket.org/drjdpowell/jsontext/src/default/Variant to JSON Text.vi

and here: https://bitbucket.org/drjdpowell/jsontext/src/default/JSON text to Variant.vi

If you look for every case structure using the type enum, find the case for "extended precision" and then add "Fixed Point" to the same case. Numeric variants automatically coerce so it should work as simple as that. (I suggest extended because of the different variations of fixed point, potentially using 64 bits in a more efficient manner than say a 64 bit double. You will still possibly lose precision)

I already fixed it, but I presumed this should be fixed in the master branch as well.

Link to post
Share on other sites
  • 3 weeks later...
Quote

JSONtext VIs

The Flatten/Unflatten String palette includes a link to install JSONtext VIs for programmingJSON in LabVIEW. On the Flatten/Unflatten String palette, click Install JSONtext Add-on toinstall the JSONtext add-on from the JKI VI Package Manager (VIPM). The JSONtext VIsappear on the Addons»JSONtext palette.

[Special thanks to Dr. James David Powell, author of the JSONtext add-on.]

https://www.ni.com/pdf/manuals/371780r.pdf

yay! 🎉

too bad nxg breaks the code

Edited by smithd
  • Like 1
Link to post
Share on other sites
7 hours ago, smithd said:

The JSONtext VIs appear on the Addons»JSONtext palette.

As of the latest Tools Network version, the palettes should also appear in the "Flatten/Unflatten String>>JSONtext" palette, in place of the install link in LabVIEW 2019.  It's programmatically added, so let me know if that doesn't work for you.

  • Like 1
Link to post
Share on other sites
  • 3 weeks later...

I am having an issue where the parser is error-ing out on building my JSON string, and I cannot figure out why.

I am trying to build a JSON structure used as part of our data logging process.  The parser is giving me the following error:

 

JSONtext.lvlib:Find Object Item Locations by Names.vi<ERR>
State: Parser Error
Near: '{
  "ProductTypeId":11,
  "ItemNum":"12345-111",
  "Sn":"132465",
  "SerialType":M'
in '{
  "ProductTypeId":11,
  "ItemNum":"12345-111",
  "Sn":"132465",
  "SerialType":MFG,
  "Guid":null,
  "Quantity":null
}''

image.png.ef5dab46db38309673dee0570379f907.png

Make Components Array in JSON.vi

Link to post
Share on other sites
  • 2 weeks later...
13 hours ago, drjdpowell said:

Sure.   I suspect smithd already has a backsaved version, so you might ask him.

afraid not, I moved on to 2017. At this point I think your best bet is to use a pre-2017 version (pre-vim). You can backsave but the vims make it annoying.

 

If you are windows-only, I think the labview runtime now supports several versions back and forth, so it might be possible to build the 2017 library into a packed library (very much like a dll, but pure labview code) and reference that. Probably not worth it though. 2015 is 4 years old at this point, might be worth investigating an update.

Edited by smithd
Link to post
Share on other sites
1 hour ago, smithd said:

afraid not, I moved on to 2017. At this point I think your best bet is to use a pre-2017 version (pre-vim). You can backsave but the vims make it annoying.

 

If you are windows-only, I think the labview runtime now supports several versions back and forth, so it might be possible to build the 2017 library into a packed library (very much like a dll, but pure labview code) and reference that. Probably not worth it though. 2015 is 4 years old at this point, might be worth investigating an update.

Thank you for your reply - I've already tried, and succeed to downconvert it to LabVIEW 2015; everything seems to be working.

I'd rather use it as plain lvlib, because I do not prefer using packed libraries...

Thank you!

Link to post
Share on other sites

It appears that Arrays of Enums are not handled properly, or at least not in the way I expect or would like!  See the attached image for details - using JSONtext 1.3.1.84 on LV 2018.

EnumJSON.png.139b7bc5276c408cf17c3e79a6fe567e.png

  • Thanks 1
Link to post
Share on other sites
  • 4 weeks later...

Is it possible to directly access a particular object somewhere deeply nested inside the JSON text with a JSONpath that doesn't require knowledge of the complete structure?

The structure can be altered outside the application, the field however are specified in official documents and should be used.

E.g. I want to get the Packet object that has NID_MESSAGE 0.

{
	"ALE (TLE)": {
		"length": 48,
		"message_type": 3,
		"FIE-PR": {
			"type": 198,
			"length": 37,
			"TCEPID": 1987771643,
			"UNISIG-037 SaPDU": {
				"ETY": 0,
				"type": 5,
				"DF": 0,
				"UNISIG-026 Message": {
					"NID_MESSAGE": 136,
					"L_MESSAGE": 24,
					"T_TRAIN": 13969,
					"NID_ENGINE": 103,
					"Packets": [{
						"NID_PACKET": 0,
						"L_PACKET": 114,
						"Q_SCALE": 0,
						"NID_LRBG": 6980601,
						"D_LRBG": 11133,
						"Q_DIRLRBG": 0,
						"Q_DLRBG": 0,
						"L_DOUBTOVER": 0,
						"L_DOUBTUNDER": 0,
						"Q_LENGTH": 0,
						"V_TRAIN": 0,
						"Q_DIRTRAIN": 0,
						"M_MODE": 0,
						"M_LEVEL": 3
					}]
				},
				"MAC": "368268A6E6112334"
			}
		}
	}
}

 

Link to post
Share on other sites

I haven't (yet) implemented an "any depth" wildcard character, but if you know how many levels down the item is, you can use wildcards for each level:

$.*.*.*.*.NID_PACKET

 

 

 

Link to post
Share on other sites

Let me, please, also ask a question regarding the toolkit.

Currently to prettify JSON string, I use function Reformat.vi. But, no matter which value of "Pretty Print Levels" I set, the output is the following:

{
  "Item":{
    "Property1":{"Name":"Property1 Name","Active":true},
    "Property2":{"Name":"Property2 Name","Active":true},
    "UID":43,
    "Active":true
  }
}

But, I'd like to have it as the following (with prettified nested objects):

{
  "Item": {
    "Property1": {
      "Name": "Property1 Name",
      "Active": true
    },
    "Property2": {
      "Name": "Property2 Name",
      "Active": true
    },
    "UID": 43,
    "Active": true
  }
}

Is it the expactable behavior, or some kind of bug - that somehow it does not prettify nested JSON objects...

JSON itself I generate using Unflatten JSONpath Array to Object.vi function - as inputs I set JSON paths, and values - and after that, Reformat.vi is applied...

Thanks a lot in advance,

Sincerely, Ivan.

Edited by kosist90
Link to post
Share on other sites

The "pretty print" includes a length check, and keeps small objects compact.  You can see it in the code; it's 40 characters or less, I think.  This was added to improve the readability of arrays of small objects.  

Unfortunately, "pretty" is subjective, and it is hard to come up with simple rules that work for all possible input JSON.

Link to post
Share on other sites
9 minutes ago, drjdpowell said:

The "pretty print" includes a length check, and keeps small objects compact.  You can see it in the code; it's 40 characters or less, I think.  This was added to improve the readability of arrays of small objects.  

Unfortunately, "pretty" is subjective, and it is hard to come up with simple rules that work for all possible input JSON.

Thanks a lot! Now I see - I didn't know, that there is no exact standart for it.

Link to post
Share on other sites

Just small recommendation to change the library.

Concerning timestamp to string conversion:

The current format string "%Y-%m-%dT%H:%M:%S%3uZ" in "Variant to Json Text.vi" is dependent on localization. On my german windows this leads a to timestamp according to Iso 8601 of "2019-07-26T14:17:20,053Z". Notice the comma for the fractional seconds. According to the Iso both, comma and point, is valid (Apparently, the Iso even recommends the comma https://en.wikipedia.org/wiki/ISO_8601#cite_note-25). However, it seems that the point is used more regularly in practice, for example in .net (see Json.net package). So I would suggest to change the format like this: "%Y-%m-%dT%H:%M:%S%.;%3uZ". This ensures using the point instead of comma., hence the format is independent of your local setting.

Link to post
Share on other sites
  • 1 month later...

Hi,

I was trying to implement this, can anyone help me with how to do it?

  "outputs": [
    [
      {
        "name": "Power",
        "value": 1.4,
        "operation": "GREATER_THAN_OR_EQUAL"
      },
      {
        "name": "Power",
        "value": 2.3,
        "operation": "LESS_THAN_OR_EQUAL"
      }
    ]
  ]

 

Thanks & regards,

Ajay

 

Link to post
Share on other sites
  • 4 weeks later...

Thanks for the great tool! It's sooo much better than mangling JSON by hand.

I have an issue with the tool not handling variant data correctly. I have a cluster with a string and a variant. When flattened to JSON the variant name is an empty string. {"SN":"2016D8A1D86C","":{"ChaSt":"Ready","LocRemCtl":"Manual"}}. The variant attributes are correctly included in an embedded JSON string, however converting back to a cluster omits the attributes.

Thanks,

Richard

 

Link to post
Share on other sites

Does your variant have a name?  If it doesn't that's why it's name is "".

Re attributes, you have to provide a variant containing default values of those attributes.  This is because the JSON doesn't contain the LabVIEW type information (can't tell a string from a timestamp from an enum).  I realize this is not the answer someone who uses variant attributes wants to here.  Personally, though, I use sub-JSON instead of variant attributes, with cluster elements that are strings with the <JSON> tag in its name.

Link to post
Share on other sites

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
      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 drjdpowell
      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. 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.]
      Submitter drjdpowell Submitted 10/04/2012 Category General LabVIEW Version  
    • 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.