[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

{“id”:“0e2ec14b-b596-42c2-99c7-038c285b1ef2”,“input”:“turn”,“intent”:{“intentName”:“pookieman:Light-On”,“probability”:0.6641376},“slots”:[],“sessionId”:“c7a5d80c-1de2-4343-993e-65076483234d”}

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

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

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

Thanks

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.