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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


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

Share this post


Link to post
Share on other sites
13 hours ago, smithd said:

too bad nxg breaks the code

working on it

  • Thanks 2

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

It's because of the lack of quotes about 'MFG'.  The first function you are using requires valid JSON values, but you are feeding it unquoted standard text.

Share this post


Link to post
Share on other sites

If I'd like to use this library in LV 2015 - is it permitted that I could re-save code to LV 2015, and use it as library there? 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
5 hours ago, drjdpowell said:

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

Thanks a lot!

Share this post


Link to post
Share on other sites
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

Share this post


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!

Share this post


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

Share this post


Link to post
Share on other sites

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"
			}
		}
	}
}

 

Share this post


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

 

 

 

Share this post


Link to post
Share on other sites

Thanks James,

Keep up the good work, it's some getting used to working with JSON in LV.

Share this post


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

Share this post


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.

Share this post


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.

Share this post


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.


×
×
  • Create New...

Important Information

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