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 comment
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 comment
  • 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 comment
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 comment
  • 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 comment
  • 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 comment
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 comment
  • 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 comment

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 comment

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 comment
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 comment

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 comment
  • 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 comment
  • 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 comment

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 comment

Join the conversation

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

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.

×
×
  • Create New...

Important Information

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