[SOLVED] Trying to read a value from JSON - what am I doing wrong here?

Hi - hope someone can point me in the right direction. I have a mqtt item which is receiving json that looks like


I know this as my rule is printing this to the log like this

rule "study light rule"
    Item Study_Light changed
    val String json = String.valueOf(Study_Light.state)
    val String newValue = transform("JSONPATH", "$.intent.intentName", json)
    logWarn("Raw Json", json)
    logWarn("Intent Field", newValue)

but I expect the field newValue to only return the intentName value but when I output it - it returns the whole json blob, what am I doing wrong? I tried with the json validator and it seems to work


Did you install the JSONPATH transformation?
What is the second logWarn giving you?

Argh!!! That was it … it wasn’t installed it… the thought did occur to me that perhaps the lib/function wasn’t available… but I wasn’t getting an error so I just assumed it was… the coding bit is easier (being an ex-java dev) than learning the nuances of OH …

thank you so much for the quick answer!

1 Like

Please tick the solution mark under the relevant post.