From Saturday, Nov 23rd 7:00 PM CST - Sunday, Nov 24th 7:45 AM CST, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

JDP Science Tools

cancel
Showing results for 
Search instead for 
Did you mean: 

JSONtext Path with dot in name

Solved!
Go to solution

I'm using JSONtext to retrieve data from a JSON file (JSON from another source).

The JSON items have dots in their name, for example:

{
  "Header": {
    "ecat.cmd": [
      "04",
      16,
      4
      ],

...

 

When using $. path notation, the dots represents breaks between names, but above you can see an entity with a dot in the name itself, so this doesn't work: 

Thoric_0-1680521468585.png

 

Google suggests that you can escape the dot in the JSON path: $.Header.ecat\.cmd

Also, it suggests you can encapsulate: %.Header.\"ecat.cmd\"

Neither works. Is there an expected nomenclature for this in JSONtext?

Thoric (CLA, CLED, CTD and LabVIEW Champion)


0 Kudos
Message 1 of 4
(2,982 Views)
Solution
Accepted by topic author Thoric

Try this:

$.Header."ecat.cmd"

0 Kudos
Message 2 of 4
(2,956 Views)

This is how it is described in the extended help (though perhaps this is not clear enough):

Object items can also be specified as their proper JSON string.   This allows the use of characters in names that would otherwise not parse correctly.  For example:

$."My Name that contains \"quotes\", []brackets, and dots." 

Note that this must be proper JSON (thus the escaped quotes in the example).

Note that JSONpath doesn't have an actual specification, so I have not held to anyone else's ideas too closely.  Rather than make up a whole set of escaping rules specific to JSONpath, I instead defined the path as using JSON Strings, with unquoted LabVIEW strings as an option, just for convenience.   The real path is $."Header"."ecat.cmd".

Message 3 of 4
(2,950 Views)

Thanks. Now that you've explained it I can see what the help means, but I think I would never have realised otherwise. It could use some rework, maybe breaking the example into three and showing that quotes around the names are equally valid (and arguably better).

Thoric (CLA, CLED, CTD and LabVIEW Champion)


0 Kudos
Message 4 of 4
(2,942 Views)