JsonPath Transformation Service

Transforms a JSON structure on basis of the JsonPath expression to an JSON containing the requested data.


Basic Example

Given the JSON

[{ "device": { "location": "Outside", "status": { "temperature": 23.2 }}}]

the JsonPath expression $.device.location exstracts the string instead a valid JSON [ "Outside" ], see differences.


the JsonPath expression $.device.status.temperature exstracts the number instead a valid JSON [ 23.2 ], see differences.


In Setup


String  Temperature_json "Temperature [JSONPATH($.device.status.temperature):%s °C]" {...}
Number  Temperature "Temperature [%.1f °C]"


rule "Convert JSON to Item Type Number"
    Item Temperature_json changed
    // use the transformation service to retrieve the value
    val newValue = transform("JSONPATH", ".$.device.status.temperature", Temperature_json.state.toString)

    // post the new value to the Number Item
    Temperature.postUpdate( newValue )

Now the resulting Number can also be used in the label to change the color or in a rule as value to compare.

Differences to standard JsonPath

Returns null if the JsonPath expression could not be found. Compared to standard JSON the transformation it returns evaluated values when a single alement is retrieved from the query. Means it does not return a valid JSON [ 23.2 ] but 23.2, [ "Outside" ] but Outside. This makes it possible to use it in labels or output channel of things and get Numbers or Strings instead of JSON arrays. A query which returns multiple elements as list is not supported.

Further Reading

  • An extended introduction can be found at W3School.
  • As JsonPath transformation is based on Jayway using a online validator which also uses Jaway will give most similar results.