Jump to content

Recommended Posts

  • 2 weeks later...

 

On 8/5/2021 at 10:29 AM, drjdpowell said:

Consider just not including those parameters.  Rather than {"A":123,"B":null,"C":789} just have {"A":123,"C":789}; then "B" will be default.

Alternately you could put named-Variant values inside your variants (which teh Variant-to-Data node will pass through:

1090371450_2021-08-0517_26_42-Untitled2BlockDiagramonJSONtext.lvproj_MyComputer_.png.63907e2224240eac829f7dadb8bfa9d8.png

Variants are quite tricky, as they can serve both as a temporary container for a value, and a value itself.

This is opposite of what I would expect to see. Fundamentally if I give you a cluster with named items (who cares about the data type), I expect the JSON output to an object with fields matching the names of the clusters. All of this "variants have names" discussion is optimizing of weird LabVIEW shenanigans instead of a primary use case.

 

On 8/5/2021 at 10:19 AM, Aristos Queue said:

Allow me to rephrase then.

Recording an array when passed a NAMED cluster is definitely a bug, regardless of the behavior of the variants.

+1

Link to comment

The following VIs aren't reentrant but should be:

- JSONtext.lvlib:Format JSON Array Text.vi
- JSONtext.lvlib:Parsing Error.vi
- JSONtext.lvlib:Format JSON Object.vi
- JSONtext.lvlib:Get all Object Items.vi
- JSONtext.lvlib:Get Array Elements.vi
- JSONtext.lvlib:Parsing Error in converting to LabVIEW type.vi

Link to comment

Does anyone actually use Variants in clusters in this way?  To me, this is not even a tertiary use case of JSONtext, so it would be helpful to hear from people with real-world uses.  I am tempted to suggest throwing a "Variants not supported" error, but even that would add overhead which I am loath to do.

Link to comment
20 minutes ago, drjdpowell said:

Does anyone actually use Variants in clusters in this way?  To me, this is not even a tertiary use case of JSONtext, so it would be helpful to hear from people with real-world uses.  I am tempted to suggest throwing a "Variants not supported" error, but even that would add overhead which I am loath to do.

I've used them in that way pre-maps leveraging variant attributes. Don't expect JSONtext to handle that use case, though.

Link to comment
  • 1 month later...
15 hours ago, Michael Aivaliotis said:

is it possible to improve the error handling for empty strings? Perhaps have a special error code I can filter on if an empty string is detected?

 

image.png

Use case?   Why do you need different custom error than the 402841: "Invalid JSON formatting" that you have now?

Link to comment
On 10/11/2021 at 1:34 AM, Michael Aivaliotis said:

is it possible to improve the error handling for empty strings? Perhaps have a special error code I can filter on if an empty string is detected?

How about wiring the string into a case structure selector?

  • Case "": Do your special output
  • Case Default: Wire the string into the JSON VIM
Link to comment

Yes, empty string is invalid JSON, but so could be malformed text, which is more serious than an empty string which could imply reading a non-existent JSON item.

How should I handle reading JSON files where data elements are missing? I like having the default data input so if an item is missing, it returns the default, of course. But now I have to write special code for every node. What is the best practice when using this toolkit for this use-case?

I guess I could create custom wrappers. But I wanted to avoid the extra work for something that's common.

Am I using it wrong?

Link to comment
5 hours ago, Michael Aivaliotis said:

How should I handle reading JSON files where data elements are missing?

Missing as in "field does not exist in the object", or missing as in "field exists but the value is an empty string"?

  • The latter is not truly missing. It exists, and its value is an empty string.
  • The former can be handled using the "Data Type and Default Value" inputs

1344596818_MissingJSON.png.6295ac54b049d6fa13467c4b182582cb.png1456594771_MissingJSONOutput.png.d52056df16414281a474f4bcf14469db.png

 

5 hours ago, Michael Aivaliotis said:

an empty string which could imply reading a non-existent JSON item.

Sounds like you're using "Find Item.vim"? Make use of the "Found" output, OR switch to "Find Item (as LVtype).vim" to specify the default value.

 

6 hours ago, Michael Aivaliotis said:

I guess I could create custom wrappers. But I wanted to avoid the extra work for something that's common.

How do you envision providing the default value if you are able to filter out the proposed "Empty String" error?

Link to comment

JKSH has explained as well as I could the expected use.  "Missing from Object" is determined when operating on the Object.  

I had a look, and it should be reasonably easy to give a different error for a string with only whitespace, but I'll need to understand use case for it better.  I, personally, never find the need to write custom error-handling code.

By the way, if one's use case is "set from this JSON as much as possible, or use supplied default for items where this is not possible", then one can just not use the error wires at all.

Edited by drjdpowell
Link to comment
  • 1 month later...

Hi, I am trying to filter an Array like this:

 

[    {
    "folder" : "User/Admin/UserA",
    "User" :  "Linda"
},
 {
    "folder" : "User/Service/UserB",
    "User" :  "John"
},
{
    "folder" : "User/Admin/UserC",
    "User" :  "Peter"
} ]

 I want to get a Array with all Clusters where folder contains "Admin"

This $Path gives me one result in my case.
$..[?(@.folder=="User/Admin/UserA")]

How can I receive all folders? Something like  $..[?(@.folder=="User/Admin/*")] isn't working. Are regEx operators (=~) or the query command contains not working?

Thank you,

Albert

Link to comment
2 hours ago, SahnAlbert said:

I want to get a Array with all Clusters where folder contains "Admin"

I don't have the filtering syntax of JSONpath yet implemented in JSONtext.  In fact, you surprised me by seeming to indicate that $..[?(@.folder=="User/Admin/UserA")] actually works, when it doesn't.  At some point I may have teh time to implement that, but in the meantime consider filtering code in LabVIEW like this

 

2021-11-30 08_45_02-Untitled 2 Block Diagram on Untitled Project 1_My Computer _.png

Link to comment
  • 4 months later...

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.