Datacake - Payload Decoder

I am having difficulty with decoding in Datacake.

This is the JSON data in my integration:

[
{
"device":{{{datacake_serial}}},
"field": "COUNTER",
"value": {{{counter}}},
"field": "PH",
"value": {{{Cur_pH}}}
}

*
]*

I believe my integration is working fine as when click Show logs in the payload decoder I can see the raw content:

[
    {
        "device": xxxxxxxxxxxxxxxxxxxx,
        "field": "COUNTER",
        "value": 15,
        "field": "PH",
        "value": 9.86
    }
        
]

In the fields I have both PH and COUNTER set up.

I have used the basic decoder from the particle tutorial - but I don’t see anything appearing in the Debug Log. If I hit “Try Decoder” I get

Code error: threw error: SyntaxError: unexpected end of JSON input

Any help getting past this would be appreciated.

Thanks, Paul

It sounds like you don't have the body set correctly in the Datacake try decoder. What do you have in the body box?

Rick,

I am able to get the test to respond but I am loosing information.

In the body I have a copy of the data that is coming through when I look at the Show logs:

[
    {
        "device":"xxxxxxxxxxxxxx",
        "field": "COUNTER",
        "value": 36,
        "field": "PH",
        "value": 4.58
        
    }
        
]

the decoder is:

function Decoder(request) {

   // Parse JSON into Object
   var payload = JSON.parse(request.body);
   console.log(payload.device)
   return payload
}

when I try decoder

the output is:

[
{
"device": "xxxxxxxxxxxxxxxxx",
"field": "PH",
"value": 4.58
}
]

It appears to loose the first field and value. Also in the recognised measurements I only get one value.

PH = 4.58 (time: auto)

Nothing in the console.log.

If I switch the field/value pairs I get the last pair - I am sure this is something simple but I cant see it. I’ve looked at the link you suggested but was a little confused so went to Incoming Webhooks | Datacake Docs - I am starting to get an understanding but still dont know why I cant get anything to appear in the console.log or why it is chopping off the data

Keys in JSON must be unique. You need to name the keys differently. Typically you'd use something like this instead:

    {
        "device":"xxxxxxxxxxxxxx",
        "COUNTER": 36,
        "PH": 4.58        
    }

Rick,

That helped a lot - not sure why I went down the rabbit hole of having “field” and “value” on every line. I can now decode the data but its still not appearing in the Datacake data.

When using try decoder I see the items in Recognized measurements but no tag for device. I am probably trying to fix something that is broken - it may be best to start a fresh with something even simpler.

Thanks, Paul