HTTP in handling JSON Object via POST

Hi,

I have been using the http request node to get JSON data from solar inverters which works fine and returns an object as can be seen here:

(ok, seems I can only post one image)

I now want to use the http in node to receive POST data pushed from the inverters, however the data in the object is not accessible. I have spent about 6 hours trying everything that I can think of in node-red to access this data but no success.

Here is the flow and what I get when set to object and string. It seems the object that is returned contains the object that I am interested in but wrapped in something else?

http in -> JSON -> http endpoint

Any advice on what I am doing wrong here would be appreciated.

Cheers,

RC

Hi,

your payload there is an object with a single key/value. The key is the JSON encoded javascript object containing your actual data. Very weird.

To access it, you’d need to do something like this:

var keys = Object.keys(msg.payload);
msg.payload = JSON.parse(keys[0]);
return msg;

But I’d also investigate quite how your data is getting into that form to begin with.

Thank you Nick!

I figured it was something like that and tried parsing but clearly incorrectly.

Unfortunately I don’t have any control over what the inverter POSTS but it is strange that the result is different between a GET and a POST.

Cheers,

RC