This section describes an example of using JSONPath().

If the sensor data (cv.Payload) or the argument of the action to be executed in the trigger condition (tv.Data) is in JSON format, you can use JSONPath() to refer to the value.

Sample Data

{ "store": {
    "book": [ 
      { "category": "reference",
        "author": "Nigel Rees",
        "title": "Sayings of the Century",
        "price": 8.95
      { "category": "fiction",
        "author": "Evelyn Waugh",
        "title": "Sword of Honour",
        "price": 12.99
      { "category": "fiction",
        "author": "Herman Melville",
        "title": "Moby Dick",
        "isbn": "0-553-21311-3",
        "price": 8.99
      { "category": "fiction",
        "author": "J. R. R. Tolkien",
        "title": "The Lord of the Rings",
        "isbn": "0-395-19395-8",
        "price": 22.99
    "bicycle": {
      "color": "red",
      "price": 19.95

For example, if you want to refer to store -> bicycle -> color , use

But if you use JSONPath() you can write

JSONPath("$.store.bicycle.color", cv.Payload)

It can also be written as

The first argument of JSONPath path

path Description
$ root object/element
@ current object/element
. or [] child operator
recursive descending
[] subscript operator (native array operator)
[,] union operator (alternative names or array indices can be used as sets)
[start:end:step] array slice operator
?() filter (script) expression
() Script expression using the underlying script engine

Example of the first argument path of JSONPath

Example Description
$[*].author all authors in the books array in the store
$ all authors
$.store.* the books array in the store and bicycle
$.store..price all prices in the store
$ [2] the third book
$[(@.length-1)]$[-1:] last book
$[0,1] $ [:2] first two books in book array
$[?(@.isbn)] all isbn in book array
$[?(@.price<10)] price less than 10 in book array
$..* all nodes/elements

For more information on JSONPath, see the reference here.

Need more help with this?
Join our slack community for help

Was this helpful?

Yes No
You indicated this topic was not helpful to you ...
Could you please leave a comment telling us why? Thank you!
Thanks for your feedback.