Help with JSON payload and items

I receive this string of data from my MQTT input:


It represents three zones of a HVAC unit and the set points for cooling and heating in those zones.

I’m trying to extract zone1’s cooling set value to display in the BASIC UI with this items config:

String zone1cool "zone1cool"

I get this error:

2018-04-22 21:37:18.007 [ERROR] [.mqtt.internal.MqttMessageSubscriber] - Error processing MQTT message.
org.openhab.core.transform.TransformationException: Invalid path ‘$’ in ‘{“z1”:{“cool”:82,“heat”:67},“z2”:{“cool”:77,“heat”:67},“z3”:{“cool”:76,“heat”:68}}’
at org.openhab.core.transform.TransformationHelper$TransformationServiceDelegate.transform( [207:org.openhab.core.compat1x:2.2.0]
at org.openhab.binding.mqtt.internal.MqttMessageSubscriber.processMessage( [222:org.openhab.binding.mqtt:1.11.0]
at []
at org.eclipse.paho.client.mqttv3.internal.CommsCallback.deliverMessage( []
at org.eclipse.paho.client.mqttv3.internal.CommsCallback.handleMessage( []
at []
at [?:?]

I’d appreciate help in understanding what needs to happen and what I don’t understand correctly.

Ultimately, I’d like to display zone1 2 and 3 cooling set points and heating set points from this string of data. What’s the best way to do this in BasicUI? Set up Items for each: z1cooling, z1heating, etc… or is there another method to do this?

thank you for the help.

What did you need to subscript for in order to get the posted JSON-string?

Your JSON path is correct.
Your JSON payload formatting is incorrect and cannot be parsed for processing.

It contains down and up double quotes and
It should only contain " vertical double quotes (“The normal ones I use here”)
What is the device you receive the JSON from?

If you can’t change the output from your device the JSONPATH transform will not work and your need another way.
Use a Javascript transform
In your tranform folder create a file called hvacz1cool.js with the following content:

function(i) {
    var str = i;
    str = str.replace(/“/g,'\"'); // Replaces ALL “ with "
    str = str.replace(/”/g,'\"'); // Replaces ALL ” with "
    output = JSON.parse(str); // Parses the now valid JSON into a javascript object
    return; // Retrieves and returns the wanted data

And the you need to change your Item definition to:

String zone1cool "zone1cool" { mqtt="<[NikMQTT:dhstddit/feeds/zone:state:JS(hvacz1cool.js)]" }

Good luck

I learned something!

I was trying to send test data through to OH and didn’t know the quotes were different. I’ve verified the program that creates the JSON it supplies proper quotes in the payload.

The error message just didn’t provide me (a novice) any insights to the problem.

I was able to change the quotes and it all worked perfectly! Thank you.