Jump to content


  • Posts

  • Joined

  • Last visited

  • Days Won


drjdpowell last won the day on July 27

drjdpowell had the most liked content!


Profile Information

  • Gender
  • Location
    Oxford, UK

LabVIEW Information

  • Version
    LabVIEW 2017
  • Since

Recent Profile Visitors

10,914 profile views

drjdpowell's Achievements

  1. Again, Variants are tricky, and have two names and serve two purposes. Viewed as a container of named data, your Variants are just placeholders, not actual data themselves (which is why I suggested in the last post to put a named Variant as Data inside the placeholder).
  2. 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: Variants are quite tricky, as they can serve both as a temporary container for a value, and a value itself.
  3. LabVIEW Clusters and Arrays do not map directly onto JSON Objects and Arrays. LabVIEW Clusters are fixed-size ordered sets of optionally-named values JSON Objects are variable-size, unordered sets of must-be-named values LabVIEW Arrays are variable sized ordered sets of values all the same type JSON Arrays are variable sized ordered sets of values that can all be different type So a LabVIEW Cluster with unnamed elements cannot map onto a JSON Object, but can map onto a JSON Array. Similarly, mixed-type JSON Arrays cannot be converted to a LabVIEW array, but can be converted to a LabVIEW cluster (assuming you know the number of elements and types). JSONtext thus supports two mappings for LabVIEW Clusters, as explained in Help>>JDP Science>>JSONtext...
  4. People who wish to use Variants and JSON generally want to do this: Put Static-Typed Data in a Variant in a larger data structure Convert larger structure to JSON Send the JSON somewhere Convert JSON back to larger structure (containing Variant) Convert Variant to Static-Typed Data But Step (4) is a big problem, as at that point we don't have access to the Type-description information to rebuild the Variant. But I say do this: Convert Static-Typed Data to JSON Assemble larger JSON from this subJSON Send the JSON somewhere Extract the subJSON Convert subJSON to Static-Typed Data This avoids the problem, as we only need the Type at the first and last steps,where we statically know the type.
  5. I've had multiple requests to "support Variants", but there is a mismatch between Variants (Data plus full type description including name) and JSON (Data with only weak type info: string, number, etc.). To support unflattening JSON to Variant would require a form something like this: { "VarA":{"Variant type":"long","name":"TypedA","Value":123}, "VarB":{"Variant type":"long","name":"TypedB","Value":456} } But this is a rabbit hole I'm not going down. I'd rather ask "Why are you using Variants here instead of subJSON?" This gives you the behaviour you expect:
  6. That is arguably not a bug, as Variants involves two names: the name of the Variant, and the name of the data contained in the Variant. In your case your empty Variants contain unnamed void data, and JSONtext flattens clusters of unnamed elements as JSON Arrays. It is not obvious if it is the best choice to use the data name rather than the Variant name. However, I am sort of tied to the behaviour of the Variant-to-Data node that I use internally to convert Clusters to Arrays of Variants. See this example: Note that Typed clusters and Clusters of Variants containing Typed Data both convert identically, while Variant elements of a cluster never retain the names of the Variants themselves, just the name on the Data in the Variant). The produced JSON matches these choices, made by the programmers of the Variant-to-Data node.
  7. The Object thing is not where I would spend limited effort in performance improvements, as I would expect the User to actually use the item Values and thus require a copy at some point. I would rather improve the JSONpath search algorithm.
  8. I hope Users can do whatever they want using the lower-level functions plus subJSON with the <JSON> tag.
  9. There is support for Sets and Maps in the latest version; I wouldn't want such things require any kind of "hook".
  10. Alternative (6): all attributes are returned as JSON values. Rather than get the attribute as the actual type, the User would get the attribute as a string, then use From JSON to convert to type. One could make VIMs that combine these two steps, and these VIMs might possibly be made to work with non-JSON attributes as well.
  11. The To-JSON behaviour was copied from the previous LAVA-JSON library. That library had the reverse operation, but it only worked if one provided same-named attributes in the default value. As you point out, this is because we need to know what type to convert the JSON to. Personally, I found this kind of useless, as the whole point of attributes is to have unknown items of unknown type. I had also developed "subJSON" for exactly this use case, and never use Variant Attributes at all. So it kind of got stuck in limbo. I note that the newer Set and Map support doesn't run into this issue, as Sets and Maps have Type. Options: Leave as is, not really supporting Variant Attributes Deprecate the current To-JSON support and fully not support Attributes at all Save Type in the JSON somehow (I don't like this) Use limited JSON types when converting from JSON: String, Float, Boolean As in LAVA-JSON, but using (4) as a fall back if type not supplied Added later: see https://bitbucket.org/drjdpowell/jsontext/issues/39/support-json-to-variant-when-no-datatype where it was proposed to do (4), I think.
  12. That is a case that needs (at least) a better error. Try the path $."" By using the quotes, the name is any JSON string, and can thus handle any name. The unquoted form is for convenience and can't handle all edge cases. BTW, what JSON are you feeding in to that node. It has to be an Object if you want to insert at $.""
  13. Note: latest version supports comments. https://forums.ni.com/t5/JDP-Science-Tools/BETA-version-of-JSONtext-1-6/m-p/4146235#M39
  14. Ah, this can be illustrated with this image: JSONtext does not follow the common error rule of returning default value on any error. Instead, it returns best-efforts, with only sub-elements that produce errors being returned as the supplied default. Here it is only the "B" element, requested as a Float but a String in the JSON, that is returned as default (as explained in the error message). Thus we are doing the Variant-to-Data even on error, in order to get this partial conversion of JSON to Data.
  15. This was originally a method in the early prototype API of JSONtext (pre public release), which is why it has a "default" input. However, I used this (now private) method internally whenever a LabVIEW type is stored as a JSON string (should really have made a separate method). In such use, I found a problem of needing a better description of the error if conversion failed, and for that I needed the actual LVtype. This is not really how I would design it from scratch, but it happened incrementally.
  • Create New...

Important Information

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