smithd Posted May 3, 2019 Report Posted May 3, 2019 (edited) 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 May 3, 2019 by smithd Quote
RogerSaele Posted May 3, 2019 Report Posted May 3, 2019 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. Quote
smithd Posted May 21, 2019 Report Posted May 21, 2019 (edited) 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 May 21, 2019 by smithd 1 Quote
drjdpowell Posted May 21, 2019 Author Report Posted May 21, 2019 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. 1 Quote
drjdpowell Posted May 21, 2019 Author Report Posted May 21, 2019 13 hours ago, smithd said: too bad nxg breaks the code working on it 2 Quote
dblk22vball Posted June 7, 2019 Report Posted June 7, 2019 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 }'' Make Components Array in JSON.vi Quote
drjdpowell Posted June 7, 2019 Author Report Posted June 7, 2019 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. Quote
kosist90 Posted June 20, 2019 Report Posted June 20, 2019 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? Quote
drjdpowell Posted June 20, 2019 Author Report Posted June 20, 2019 Sure. I suspect smithd already has a backsaved version, so you might ask him. Quote
kosist90 Posted June 20, 2019 Report Posted June 20, 2019 5 hours ago, drjdpowell said: Sure. I suspect smithd already has a backsaved version, so you might ask him. Thanks a lot! Quote
smithd Posted June 21, 2019 Report Posted June 21, 2019 (edited) 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 June 21, 2019 by smithd Quote
kosist90 Posted June 21, 2019 Report Posted June 21, 2019 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! Quote
GregSands Posted June 26, 2019 Report Posted June 26, 2019 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. 1 Quote
andre@carya Posted July 18, 2019 Report Posted July 18, 2019 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" } } } } Quote
drjdpowell Posted July 18, 2019 Author Report Posted July 18, 2019 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 Quote
andre@carya Posted July 19, 2019 Report Posted July 19, 2019 Thanks James, Keep up the good work, it's some getting used to working with JSON in LV. Quote
kosist90 Posted July 19, 2019 Report Posted July 19, 2019 (edited) 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 July 19, 2019 by kosist90 Quote
drjdpowell Posted July 19, 2019 Author Report Posted July 19, 2019 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. Quote
kosist90 Posted July 19, 2019 Report Posted July 19, 2019 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. Quote
andy_r Posted July 26, 2019 Report Posted July 26, 2019 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. Quote
Ajay Yadiki Posted September 11, 2019 Report Posted September 11, 2019 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 Quote
Richard_Jennings Posted October 7, 2019 Report Posted October 7, 2019 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 Quote
drjdpowell Posted October 7, 2019 Author Report Posted October 7, 2019 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. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.