# Webhook not parsing data JSON

**URL:** <https://community.particle.io/t/webhook-not-parsing-data-json/14914>\
**Category:** Troubleshooting\
**Created:** [August 31, 2015, 2:50am UTC](https://community.particle.io/t/webhook-not-parsing-data-json/14914 "2015-08-31T02:50:13Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![javo](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/javo/32/6606_2.png) [@javo](https://community.particle.io/u/javo)\
**Post date:** [August 31, 2015, 2:50am UTC](https://community.particle.io/t/webhook-not-parsing-data-json/14914/1 "2015-08-31T02:50:13Z")

</div>

This is my webhook definition:

```
{
    "event": "measure",
    "url": "http://www.mysite.com/v1/measure",
    "requestType": "POST",
    "mydevices": true
}

```

And my firmware code:

```
Particle.publish(
    "measure", 
    "{\"value1\": " + String(currentValue1, 2) + 
        ", \"value2\": " + String(currentValue2, 2) +
        "}",
    60,
    PRIVATE
);

```

My problem is that in the server I get the “data” field as a plain string containing the JSON:

```
{ event: 'measure',
  data: '{"value1": 31.00, "value2": 30.00}',
  published_at: '2015-08-31T02:47:59.976Z',
  coreid: '1axxxxxxxxxxxxxxxxxxxxxxxxx' }

```

Am I supposed to parse it manually on server side or it should be already come in JSON format?

Thanks

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [August 31, 2015, 6:13am UTC](https://community.particle.io/t/webhook-not-parsing-data-json/14914/2 "2015-08-31T06:13:30Z")

</div>

Your event looks very much like a custom template, so you should provide a definition for it in your webhook.  
You could either “hand parse” it yourself or provide the full webhook definition.

Have a look at the docs here  
[https://docs.particle.io/guide/tools-and-features/webhooks/#custom-template-variables](https://docs.particle.io/guide/tools-and-features/webhooks/#custom-template-variables)

---

<div class="post-metadata">

**Author:** ![Dave](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/dave/32/181_2.png) [@Dave](https://community.particle.io/u/Dave)\
**Post date:** [September 2, 2015, 4:15pm UTC](https://community.particle.io/t/webhook-not-parsing-data-json/14914/3 "2015-09-02T16:15:24Z")

</div>

> [@javo](#):
>
> "{"value1": " + String(currentValue1, 2) +  
> ", "value2": " + String(currentValue2, 2) +  
> "}",

Hi @javo,

I think you mean:

```auto
"{\"value1\": \"" + String(currentValue1, 2) + "\"," + 
        "\"value2\": \"" + String(currentValue2, 2) + "\"}", 

```

you want the output to be:

```auto
 {"value1": "some string", "value2": "some other string" }

```

and not:

```auto
 {"value1": some string, "value2": some other string }

```

Thanks!  
David

---

<div class="post-metadata">

**Author:** ![javo](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/javo/32/6606_2.png) [@javo](https://community.particle.io/u/javo)\
**Post date:** [September 2, 2015, 5:10pm UTC](https://community.particle.io/t/webhook-not-parsing-data-json/14914/4 "2015-09-02T17:10:55Z")

</div>

You are right. I totally overlooked that. Thanks!  
EDIT: See below

---

<div class="post-metadata">

**Author:** ![javo](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/javo/32/6606_2.png) [@javo](https://community.particle.io/u/javo)\
**Post date:** [September 2, 2015, 5:16pm UTC](https://community.particle.io/t/webhook-not-parsing-data-json/14914/5 "2015-09-02T17:16:08Z")

</div>

Wait a second… no. I’m using String here to limit the precision digits, not because the values are strings. They are always numbers and as far as I know they are valid in a JSON file.

My output is:

```auto
    {"value1": 20.14, "value2": 19.51 }

```

---

<div class="post-metadata">

**Author:** ![Dave](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/dave/32/181_2.png) [@Dave](https://community.particle.io/u/Dave)\
**Post date:** [September 2, 2015, 5:23pm UTC](https://community.particle.io/t/webhook-not-parsing-data-json/14914/6 "2015-09-02T17:23:51Z")

</div>

Ah, nevermind then! If they’re literals and not strings, then you’re right, quotes wouldn’t be needed. 🙂

Whatever gets published, you might want to check it in a JSON validator ( [http://jsonlint.com/](http://jsonlint.com/) ).

In your hook, use the json property in the place where you want the value to be. The hook treats it like a mustache template, so something like:

```auto
{
    "event": "measure",
    "url": "http://www.mysite.com/v1/measure",
    "requestType": "POST",
    "json": {
      "value1": "{{value1}}"
    },
    "mydevices": true
}

```

Thanks!  
David

---

<div class="post-metadata">

**Author:** ![javo](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/javo/32/6606_2.png) [@javo](https://community.particle.io/u/javo)\
**Post date:** [September 2, 2015, 5:40pm UTC](https://community.particle.io/t/webhook-not-parsing-data-json/14914/7 "2015-09-02T17:40:16Z")

</div>

That must be it. Now I notice that my webhook definition was not correct. I must confess the docs are a bit confusing on this subject.

---

<div class="post-metadata">

**Author:** ![Dave](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/dave/32/181_2.png) [@Dave](https://community.particle.io/u/Dave)\
**Post date:** [September 2, 2015, 5:52pm UTC](https://community.particle.io/t/webhook-not-parsing-data-json/14914/8 "2015-09-02T17:52:21Z")

</div>

Thanks, I’ll continue to try and improve the docs! 🙂

---

<div class="post-metadata">

**Author:** ![imran445](https://avatars.discourse-cdn.com/v4/letter/i/3ab097/32.png) [@imran445](https://community.particle.io/u/imran445)\
**Post date:** [April 19, 2018, 10:39am UTC](https://community.particle.io/t/webhook-not-parsing-data-json/14914/9 "2018-04-19T10:39:05Z")

</div>

Hi @Dave  
When I provide the coordinates manually in webhook url , I got my required offset i.e -7 from the response template. But my problem is I need to update the url with the coordinates of my photon device automatically. With the help google maps api i used to get the coordinates of my photon  
device. In the 2nd screen shot u can see my location " locationCallback 12.924183,77.552666"

 ![Screenshot-2018-4-19%20Particle%20Console%20Build%20your%20connected%20product](https://us1.discourse-cdn.com/flex026/uploads/particle/original/3X/0/9/099bc420ca3ce90125c1e8b98d65cfa4ef086c6b.png)  
 ![Screenshot-2018-4-19%20Particle%20Console%20Build%20your%20connected%20product(1)](https://us1.discourse-cdn.com/flex026/uploads/particle/original/3X/0/8/0849a5157a2e00f1c97a8697b5a3dc1358e53e1a.png)  
 ![Screenshot-2018-4-19%20Particle%20Console%20Build%20your%20connected%20product(2)](https://us1.discourse-cdn.com/flex026/uploads/particle/original/3X/2/0/20709baf2c9f3062f5294278c3a04ab5ed86ddbb.png)

Can you please help me with this regard

---

<div class="post-metadata">

**Author:** ![rickkas7](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/rickkas7/32/8681_2.png) [@rickkas7](https://community.particle.io/u/rickkas7)\
**Post date:** [April 19, 2018, 11:13am UTC](https://community.particle.io/t/webhook-not-parsing-data-json/14914/10 "2018-04-19T11:13:26Z")

</div>

It looks like you just need to replace the hardcoded coordinates in the URL field for the locationCallback webhook with `{{PARTICLE_EVENT_VALUE}}`.

```auto
https://api.darksky.net/forecast/6f.....c8/{{{PARTICLE_EVENT_VALUE}}

```

---

<div class="post-metadata">

**Author:** ![imran445](https://avatars.discourse-cdn.com/v4/letter/i/3ab097/32.png) [@imran445](https://community.particle.io/u/imran445)\
**Post date:** [April 19, 2018, 11:33am UTC](https://community.particle.io/t/webhook-not-parsing-data-json/14914/11 "2018-04-19T11:33:14Z")

</div>

Thanks a lot @rickkas7 😅 for your kind help. It works like a charm. I got the output what i want.

---

<div class="post-metadata">

**Author:** ![imran445](https://avatars.discourse-cdn.com/v4/letter/i/3ab097/32.png) [@imran445](https://community.particle.io/u/imran445)\
**Post date:** [April 19, 2018, 12:00pm UTC](https://community.particle.io/t/webhook-not-parsing-data-json/14914/12 "2018-04-19T12:00:31Z")

</div>

One more request @rickkas7 , how can I store or save the offset response value so that i can use that in my coding.

---

<div class="post-metadata">

**Author:** ![imran445](https://avatars.discourse-cdn.com/v4/letter/i/3ab097/32.png) [@imran445](https://community.particle.io/u/imran445)\
**Post date:** [April 19, 2018, 12:59pm UTC](https://community.particle.io/t/webhook-not-parsing-data-json/14914/13 "2018-04-19T12:59:31Z")

</div>

Yeah I figured it out finally. So no worries. Thanks for the kind help @rickkas7 😄  
Thanks,  
Imran
