[SOLVED] How to properly parse returned JSON array

Preformatted textHey All,

I’ve been following a few threads to try and re-create the desired outcome but I haven’t quite yet got it my issue worked out.

I’m making a call to Emoncms that returns a JSON array with the code and data below.

Here is my code:

var String wattsUsedString = sendHttpGetRequest(url)
logInfo("DEBUG", "DEBUG 1: " + wattsUsedString)
var Number newValue = transform("JSONPATH", ".$[0][1]", wattsUsedString)
logInfo("DEBUG", "DEBUG 2: " + newValue)

The JSON returned value from the GET request is (DEBUG 1 printout):


Then the value printed out in DEBUG 2 is the same as the GET returned value (DEBUG 1).

I’m just having a heck of a time trying to understand why the JSONPATH isn’t working and pulling the last data value [0][1] of the array. The online JSONPath tool say that my “.$[0][1]” should be return the second value, so I’m guessing that the var type that I’m assigning it is wrong, but I’ve tried numerous types and none are working for me.

Any help or documentation would be much appreciated.

The jsonpath is incorrect, it should be $.[0][1]

var Number newValue = transform("JSONPATH", "$.[0][1]", wattsUsedString)

Thanks for the reply, but I tried with your line of code, and it is still returning


Is the variable type from the GET request suppose to be “String” or should it be “Number” or something else?

Just as an additional note, this code is taking place during a rule CRON that occurs once a day.

It works for me. I’ll double check tomorrow.

I looked at some more threads and came across someone mentioning the JSONPath binding. I didn’t realize that it was a binding that was necessary. Go figure that the simplest thing to check was the solution.

Everything is working perfectly now after installing the binding.

1 Like