Applying JS-Transformation on a JSONPATH

Tags: #<Tag:0x00007f6173de7570> #<Tag:0x00007f6173de7458> #<Tag:0x00007f6173de7390>

I’m trying to get an item automatically transformed into the right format, which I import via JSONPATH.

So, the JSON looks like this:

  "vehicles": {
    "infoTimestamp": 1592423460470

I’d like to convert this UNIX-Timestamp into ISO-Timestamp using this timestamp.js

	var otdata = JSON.parse(json);
	return new Date(otdata.tst * 1000).toISOString();

So, I figured, the item for it, should look something like:

DateTime	InfoTimestamp	"Info Zeit [%1$ta %1$tR]"	{ http="<[NIU:30000:JSONPATH($.vehicles.infoTimestamp):JS(timestamp.js)]" }

but I then get this one:

2020-06-18 08:33:44.213 [WARN ] [ab.binding.http.internal.HttpBinding] - Transformation 'JSONPATH($.vehicles.infoTimestamp):JS(timestamp.js)' threw an exception. [response={"vehicles":{"infoTimestamp":1592461860418}}]

Is there something in the syntax I missed? or can JS-transformations AND JSONPATH not work together?

OH1 http bindind supports only one transformation at the time, but you should be able do transformation purely with javascript.

    	return new Date(JSON.parse(json).vehicles.infoTimestamp * 1000).toISOString();

ok. I’d need a dedicated JS for each item, but I’ll manage.

…but is a OH2-http-binding in the making?