Parse string returned from MQTT

I am trying to parse my returned MQTT data.

Here is my MQTT command:

payload = interfaces.mqtt.parseMessage(description).payload

payload =

The response is JSON but stored as a string, not a format where I can parse it.
For example:
ProcessEvent ( "modualType" , payload.moduleType )
Returns this error: groovy.lang.MissingPropertyException: No such property: modualType for class: java.lang.String on line 104 (method parse)

I am over my head here and in learn-as-I-go mode.
How do I parse payload string to my device's current states?

Use jsonSlurper?

import groovy.json.JsonSlurper;

def jsonSlurper = new JsonSlurper()
def obj = jsonSlurper.parseText('{ "foo": "bar", "baz": [1] }')

Got the Jsonsluper working. Thanks!

def jsonSlurper = new JsonSlurper()
def jsonpayload = jsonSlurper.parseText(payload)

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.