JSONPATH transformation removes quotation marks

  • Platform information:
    • Hardware: Intel i3
    • OS: Debian
    • openHAB version: 4.1.1

Hi community,
I`m fetching the currently played song with http binding from a webradio service.
I get a json response like this:

[{"stationId":"5.0.0","id":"29440449","artist":"Leony","title":"Holding on","starttime":1710680016,"duration":172,"type":"music","cover":"https://onair.swr.de/covers/swr/swrhfdb1.KONF.50541227?stationid=28471","hook":"https://hooksswr-a.akamaihd.net/28471/1831958.m.mp3","url":{},"playingMode":2},{"stationId":"5.0.0","id":"29440441","artist":"Kenya Grace","title":"Strangers","starttime":1710679846,"duration":172,"type":"music","cover":"https://onair.swr.de/covers/swr/swrhfdb1.KONF.51268978?stationid=28471","hook":"https://hooksswr-a.akamaihd.net/28471/1918595.m.mp3","url":{},"playingMode":0},{"stationId":"5.0.0","id":"29440409","artist":"Harry Styles","title":"Watermelon sugar","starttime":1710679592,"duration":173,"type":"music","cover":"https://onair.swr.de/covers/swr/swrhfdb1.KONF.46947077?stationid=28471","hook":"https://hooksswr-a.akamaihd.net/28471/M0582167.001.m.mp3","url":{},"playingMode":0},{"stationId":"5.0.0","id":"29440406","artist":"CIVO / Maxe","title":"Keine Homies","starttime":1710679459,"duration":136,"type":"music","cover":"https://onair.swr.de/covers/swr/swrhfdb1.KONF.52158311?stationid=28471","hook":"https://hooksswr-a.akamaihd.net/28471/1989392.m.mp3","url":{},"playingMode":0},{"stationId":"5.0.0","id":"29440387","artist":"Meduza x James Carter feat. Elley Duhe & FAST BOY","title":"Bad memories","starttime":1710679295,"duration":147,"type":"music","cover":"https://onair.swr.de/covers/swr/swrhfdb1.KONF.49432357?stationid=28471","hook":"https://hooksswr-a.akamaihd.net/28471/M0687048.001.m.mp3","url":{},"playingMode":0},{"stationId":"5.0.0","id":"29440361","artist":"Coolio","title":"Gangsta's paradise","starttime":1710678967,"duration":240,"type":"music","cover":"https://onair.swr.de/covers/swr/swrhfdb1.KONF.46115928?stationid=28471","hook":"https://hooksswr-a.akamaihd.net/28471/M0519603.001.m.mp3","url":{},"playingMode":0},{"stationId":"5.0.0","id":"29440346","artist":"southstar","title":"Miss you","starttime":1710678795,"duration":200,"type":"music","cover":"https://onair.swr.de/covers/swr/swrhfdb1.KONF.49523007?stationid=28471","hook":"https://hooksswr-a.akamaihd.net/28471/1707782.m.mp3","url":{},"playingMode":0},{"stationId":"5.0.0","id":"29440328","artist":"Tate McRae","title":"Greedy","starttime":1710678660,"duration":130,"type":"music","cover":"https://onair.swr.de/covers/swr/swrhfdb1.KONF.51276203?stationid=28471","hook":"https://hooksswr-a.akamaihd.net/28471/1922743.m.mp3","url":{},"playingMode":0},{"stationId":"5.0.0","id":"29440300","artist":"RAYE feat. 070 Shake","title":"Escapism","starttime":1710678394,"duration":205,"type":"music","cover":"https://onair.swr.de/covers/swr/swrhfdb1.KONF.50648987?stationid=28471","hook":"https://hooksswr-a.akamaihd.net/28471/1903142.m.mp3","url":{},"playingMode":0},{"stationId":"5.0.0","id":"29440272","artist":"Ayliva","title":"Lieb mich","starttime":1710678216,"duration":177,"type":"music","cover":"https://onair.swr.de/covers/swr/swrhfdb1.KONF.52391402?stationid=28471","hook":"https://hooksswr-a.akamaihd.net/28471/2001467.m.mp3","url":{},"playingMode":0},{"stationId":"5.0.0","id":"29440271","artist":"Avicii feat. Sandro Cavazza","title":"Without you","starttime":1710677994,"duration":179,"type":"music","cover":"https://onair.swr.de/covers/swr/swrhfdb1.KONF.45718620?stationid=28471","hook":"https://hooksswr-a.akamaihd.net/28471/M0489572.001.m.mp3","url":{},"playingMode":0}]

I like to get the current song, which should be easy with JSONPATH.
I tried it as JSONPATH Profile ($[0]) and as Status Transformation (JSONPATH:$[0]) but the result is the same:

{stationId=5.0.0, id=29440498, artist=Armani White, title=Billie Eilish., starttime=1710680187, duration=98, type=music, cover=https://onair.swr.de/covers/swr/swrhfdb1.KONF.49560942?stationid=28471, hook=https://hooksswr-a.akamaihd.net/28471/1721871.m.mp3, url={}, playingMode=2} 

As you can see the quotation marks are removed, but I like to keep them as I want to postprocess the json data. (Widget / SQL / etc.) I can only find the other way round where people try to remove the quotation marks, which would be easy with a concated regex…

Online evaluator keeps them: https://jsonpath.com/
How can I achieve this result?

Thank you

Edit:
Got it working in a rule, but would be nicer without rule…

So why not just do it all where you post process? Pulling the first element of an array using JSONPATH only to have to parse and process the String further down the line doesn’t really buy you much.

I suspect the double quotes are removed because the JSONPATH transform assumes the result is going to be used to update an Item so maybe it strips the double quotes.

The transforms, as a general rule, are tuned for outputting Strings to update an Item and often do not fully support the full range of capabilities of the technology. I’m particular, REGEX and JSONPATH behave differently from the standards. So just because it works on an online tester doesn’t necessarily mean it’ll work in an OH transform.

Hi Rich, I store it in an sql database and it’s redundant information.
Its useless to store the last 20 values when I record every single anyway…
Every widget or graph has to load 20x overhead and split of that first element. That doesn’t make sense…

I`m aware that OH behaves sometimes different than online evaluators, just thought anyone could recommend “set switch xy and it works as you expect” or “use the latest JSONPATH transformation from repo xy”.

Thanks for your reply anyway, Jan

Seems like a different approach over all would be more effective over all. But there’s not enough info to address that. It just smells of an xy problem over all.

But ignoring all that, instead of using JSONPATH you could use a JS transform or a rule (as you’ve done above). It’s simple enough an inline JS transform might be sufficient.