Webhooks JSON seems invalid

Here is my webhook definition:

{
    "event": "checkin",
    "url": "http://myserveraddress/checkin",
    "requestType": "POST",
        "headers": {
        "Content-Type": "application/json"
        },

    "json": {
        "vbat" : "{{vbat}}",
        "soc" : "{{soc}}",
        "deviceid" : "{{SPARK_CORE_ID}}",
        "published" : "{{SPARK_PUBLISHED_AT}}",
        "event" : "{{SPARK_EVENT_NAME}}"
    },
    "noDefaults": true,
    "mydevices": true
}

In my firmware, i publish like this:

Particle.publish("checkin", "{\"vbat\":" + String(fuel.getVCell()) + ", \"soc\":" + String(fuel.getSoC()) +"}",60, PRIVATE);`

I am using nodejs and when it reaches my server, the req.body looks like this:

{ vbat: '3.945',
  soc: '87.78125',
  deviceid: 'mydeviceid',
  published: '2016-03-01T15:57:50.268Z',
  event: 'checkin' }

This does not parse and JSONLint says it is invalid (due to the lack of quotations). I am sure I ak just missing something. Any help is appreciated :smile:

interstingly, when I publish the webhook, it gives me the incorrect json format in the message:

Sending webhook request { uri: ‘/v1/webhooks’,
method: ‘POST’,
json:
{ event: ‘checkin’,
url: ‘http://myserver/checkin’,
deviceid: undefined,
requestType: ‘POST’,
mydevices: true,
headers: { ‘Content-Type’: ‘application/json’ },
json:
{ vbat: ‘{{vbat}}’,
soc: ‘{{soc}}’,
deviceid: ‘{{SPARK_CORE_ID}}’,
published: ‘{{SPARK_PUBLISHED_AT}}’ },
noDefaults: true },
headers: { Authorization: ‘Bearer xxxxxxx’ } }

I don’t have an answer to your actual problem, but as for the invalidity of the JSON: yes, it’s technically invalid. But every JSON parser should be able to handle it, because it’s a very commonly used variation.

Strictly following the spec, strings should be indicated by double quotes, not single quotes. And in an object definition, the key is a string, so therefore it should be double-quoted.

However, using single quotes is widely done. And eliminating the quotes on the keys in the object when the key consists only of alphanumeric characters is also widely done.

Thanks. It appears that it is parsing correctly. Because I was logging the json to the console and running it through JSONLint, I assumed it was invalid (well I guess technically it is), I was heading down the road of correcting it. After reading what you posted, I started writing the json to a file and of course it is working. Thanks for the response!