How to send JSON - data with nested objects?

Hi,

I try to send data via TCP API with nested objects, but can’t access them within a rule.

Example:

echo ‘{“k”: “key_here”,“d”: {“data1”: “1”, “data2” : “2” }, “t”: “TOPIC1”}’ | nc -i1 cloudsocket.hologram.io 9999

ist accepted by API.

But I can*t access data in rule with <<decdata.data1>>.
RAW-view is showing that data was’nt encoded
"data": "{\"data1\": \"1\", \"data2\": \"2\"}"

result_data":"Error decoding data for variable ‘decdata.data1’

What’s wrong?

Kind regards

Kai

Hmm can you try sending data as a json-encoded string like:
"d":"{\"data1\":\"1\"}"

Works!!!

echo ‘{“k”: “key_here”,“d”: “{"data1": "1","data2": "1"}”, “t”: “TOPIC1”}’ | nc -i1 cloudsocket.hologram.io 9999

Thank you

Kai

Ok cool, glad that’s working. We’re going to add better nested json support in there in the future

I was not able to get this working with nested JSON nor data as a JSON-encoded string. Any ideas how I might get this working? Here is the payload (w/ data as JSON-encoded string):

const char *tpl = "{ \"k\": \"%s\", \"t\": \"STATS\", \"d\": \"{ \"lat\": \"%s\", \"lon\": \"%s\" }\" }";
snprintf(state.getBuffer(), 256, tpl, HOLOGRAM_DEVICE_KEY, latBuf, lonBuf);