[Solved] Transform with JSONPATH not working? What am I doing wrong?

Hi there,

I’m trying to integrate JSON output from Snips in my openhab rules but somehow the transformation doesn’t seem to work.

The rule is the following:
var String intentName = transform("JSONPATH", "$.intent.intentName", Snips_Intent.state.toString)

And Snips_Intent.state.toString contains:

The rule should output
[ "domi:LampenAusSchalten" ]

But logInfo(“snips.rule”, "intent name: " + intentName) outputs:

As you can see it outputs the complete JSON again?
What’s wrong here? According to an online JSONPATH tester it should work?
Openhab Version 2.4

I dunno. I just did this and it works as expected.

    val s = '{
	"sessionId": "bff1ec5b-7ec4-4047-a1c1-9ca7dbd5b05c",
	"customData": null,
	"siteId": "default",
	"input": "schalte das licht im bad aus",
	"asrTokens": [
		[{
				"value": "schalte",
				"confidence": 1,
				"rangeStart": 0,
				"rangeEnd": 7,
				"time": {
					"start": 0,
					"end": 0.63
				}
			},
			{
				"value": "das",
				"confidence": 1,
				"rangeStart": 8,
				"rangeEnd": 11,
				"time": {
					"start": 0.63,
					"end": 1.02
				}
			},
			{
				"value": "licht",
				"confidence": 1,
				"rangeStart": 12,
				"rangeEnd": 17,
				"time": {
					"start": 1.02,
					"end": 1.14
				}
			},
			{
				"value": "im",
				"confidence": 1,
				"rangeStart": 18,
				"rangeEnd": 20,
				"time": {
					"start": 1.14,
					"end": 1.35
				}
			},
			{
				"value": "bad",
				"confidence": 1,
				"rangeStart": 21,
				"rangeEnd": 24,
				"time": {
					"start": 1.35,
					"end": 1.35
				}
			},
			{
				"value": "aus",
				"confidence": 1,
				"rangeStart": 25,
				"rangeEnd": 28,
				"time": {
					"start": 1.35,
					"end": 2.73
				}
			}
		]
	],
	"intent": {
		"intentName": "domi:LampenAusSchalten",
		"confidenceScore": 0.8482069
	},
	"slots": [{
		"rawValue": "bad",
		"value": {
			"kind": "Custom",
			"value": "Badezimmer"
		},
		"range": {
			"start": 21,
			"end": 24
		},
		"entity": "objectLocation",
		"slotName": "deviceLocation",
		"confidenceScore": 1
	}]
}'
    val String intentName = transform("JSONPATH", "$.intent.intentName", s)
    logInfo("test", "intentName={}", intentName)
2019-03-16 10:14:14.803 [INFO ] [.eclipse.smarthome.model.script.test] - intentName=domi:LampenAusSchalten

@mhilbush that’s weird, I get: https://gist.github.com/solars/7391af3d6456411334f82a89e3ea49fb

I’m using the latest docker version, is there anything I need to get transform to work?

@mhilbush nevermind - I uninstalled the jsonpath service and reinstalled it, and it worked :confused:

That’s weird. But, it works now… :smile:

1 Like

Please click the square box on the post that provided the solution. I edited the title to start with solved. Hopefully this will help others with a similar issue find a quick solution.

Thanks