[OH2] MQTT bindig - Select value from JSON string

Hi!
I’m very new to openHAB.
I have set up MQTT binding; from my Mosquitto server, I receive:

ab123/XBEE_A/response: {"type":146,"remote64":"0013a20040f635d0","remote16":"fffe","receiveOptions":193,"digitalSamples":{"DIO2":0,"DIO3":1},"analogSamples":{"AD1":1200},"numSamples":1}

Now, I would select the value of “DIO2” only if “remote64” has a static address.
The value selected would be a temperature sensor, or a switch on/off:

Number TestTemperature "Temperature [%.1f F]" <temperature> (GF_Living) {mqtt="<[ab123/XBEE_A/response:state:default]"}

I have read the JSONPath option, but I don’t know how to works. Can you help me?
Thanks!
Roberto

I guess you need to use transformation but I can’t help you more. I’ve never done this.

Number TestTemperature "Temperature [%.1f °F]" <temperature> (GF_Living) {mqtt="<[ab123/XBEE_A/response:state:JS(XBEE_A_Number.js)]"}

transform/XBEE_A_Number.js:

(function(json){
var response = JSON.parse(json);
if (response.remote64 == "0013a20040f635d0")  { // or whatever
  return response.digitalSamples.DIO2;
} else {
  return "Undefined";  // or "UNDEF" on OH2
}})(input)

and similar for switch, only return “ON” or “OFF” or “Undefined”/“UNDEF”

Thanks a lot!
When the Mosquitto receive data, I log this error:

17:08:23.806 [ERROR] [.mqtt.internal.MqttMessageSubscriber] - Error processing MQTT message.
org.openhab.core.transform.TransformationException: An error occured while executing script.
	at org.openhab.core.transform.TransformationHelper$TransformationServiceDelegate.transform(TransformationHelper.java:63)[177:org.openhab.core.compat1x:2.0.0.201701071314]
	at org.openhab.binding.mqtt.internal.MqttMessageSubscriber.processMessage(MqttMessageSubscriber.java:138)[176:org.openhab.binding.mqtt:1.9.0.201701070211]
	at org.openhab.io.transport.mqtt.internal.MqttBrokerConnection.messageArrived(MqttBrokerConnection.java:552)[178:org.openhab.io.transport.mqtt:1.9.0.201701070211]
	at org.eclipse.paho.client.mqttv3.internal.CommsCallback.handleMessage(CommsCallback.java:336)[178:org.openhab.io.transport.mqtt:1.9.0.201701070211]
	at org.eclipse.paho.client.mqttv3.internal.CommsCallback.run(CommsCallback.java:148)[178:org.openhab.io.transport.mqtt:1.9.0.201701070211]
	at java.lang.Thread.run(Thread.java:745)[:1.8.0_111]

If I change the Item from Number to String and I change JS(…) with ‘default’, the Item value is the JSON, so I think there isn’t problem with Mosquitto.
Even if I change the function with only “return 1”, I log the same error.

Can you help me?
Thanks!

What is the exact contents of the .js file from your transform directory?