# POST form "Unable to parse JSON body"

**URL:** <https://discourse.nodered.org/t/post-form-unable-to-parse-json-body/24988>\
**Category:** General\
**Created:** [17 April 2020 00:52 UTC](https://discourse.nodered.org/t/post-form-unable-to-parse-json-body/24988 "2020-04-17T00:52:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![VinistoisR](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/vinistoisr/32/5778_2.png) [@VinistoisR](https://discourse.nodered.org/u/VinistoisR)\
**Post date:** [17 April 2020 00:52 UTC](https://discourse.nodered.org/t/post-form-unable-to-parse-json-body/24988/1 "2020-04-17T00:52:37Z")

</div>

So I'm trying to fill out a super basic web form with a content type of "Content-Type: application/x-www-form-urlencoded; charset=UTF-8".

The page is hosted at [http://www.something.com/contact-us.html](http://www.something.com/contact-us.html), but the form POST request URL is  
[https://sitesupport-v7.websitetonight.com/api/CustomFormMailer/Submit](https://sitesupport-v7.websitetonight.com/api/CustomFormMailer/Submit)

When I fill out the form in my browser, the POST data that is sent (the object that is sent?) looks like this:

```auto
{"domainName":"something.com","resellerId":1,"elementId":"371086304","subject":"something.com Contact Us: Form Submission","emailHashList":"something@gmail.com","formFields":[{"label":"Name:","value":"myname","type":"input"},{"label":"Email:","value":"myemail@email.com","type":"email"},{"label":"Phone Number","value":"555-555-5555","type":"input"},{"label":"Address","value":"55555 road","type":"input"},{"label":"Message:","value":"order","type":"paragraph"},{"label":"Date and time","value":"04/15/2020 2:30 PM"}],"hostPageUrl":"http%3A%2F%2Fwww.something.com%2Fcontact-us.html"}

```

The page then shows a message "Thank you for contacting us! We have received your order, we will deliver your order 30 minutes."

... but that message is permanently encoded in the page, and is simply revealed when you post the form.

So I have a function node like this:

```auto
var payload = msg.payload;

var data = {"domainName":"something.com","resellerId":1,"elementId":"371086304","subject":"something.com Contact Us: Form Submission","emailHashList":"something@gmail.com","formFields":[{"label":"Name:","value":"myname","type":"input"},{"label":"Email:","value":"myemail@email.com","type":"email"},{"label":"Phone Number","value":"555-555-5555","type":"input"},{"label":"Address","value":"55555 road","type":"input"},{"label":"Message:","value":"order","type":"paragraph"},{"label":"Date and time","value":"04/15/2020 2:30 PM"}],"hostPageUrl":"http%3A%2F%2Fwww.something.com%2Fcontact-us.html"};

msg.headers = {
'content-type':'application/x-www-form-urlencoded'

}

msg.payload = data;
return msg;

```

and then an HTTP node like this:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/2/92e09c09e968aac0861e96dfd03bd241b3d38699.png)

The msg.payload object of my flow looks the same as the data above. But when I submit, I receive "Unable to parse JSON body".

Is my flow expecting a JSON response that it isn't receiving?  
Is my flow sending JSON when it should be a string?  
Is the error message sent by the server I am contacting?  
Is it working silently?

Unfortunately I don't have a way to test if its working without putting in an order for some beers lol.

The end goal is to ask google to order me some beer.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [17 April 2020 01:03 UTC](https://discourse.nodered.org/t/post-form-unable-to-parse-json-body/24988/2 "2020-04-17T01:03:23Z")

</div>

Have you tried content type

```auto
application/json

```

---

<div class="post-metadata">

**Author:** ![VinistoisR](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/vinistoisr/32/5778_2.png) [@VinistoisR](https://discourse.nodered.org/u/VinistoisR)\
**Post date:** [17 April 2020 01:22 UTC](https://discourse.nodered.org/t/post-form-unable-to-parse-json-body/24988/3 "2020-04-17T01:22:09Z")

</div>

No I have not, only because my browser REQ shows as application/x-www-form-urlencoded when it submits the form.

I guess you're thinking, the server expected JSON and is complaining that I sent it as urlencoded?

---

<div class="post-metadata">

**Author:** ![VinistoisR](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/vinistoisr/32/5778_2.png) [@VinistoisR](https://discourse.nodered.org/u/VinistoisR)\
**Post date:** [17 April 2020 01:25 UTC](https://discourse.nodered.org/t/post-form-unable-to-parse-json-body/24988/4 "2020-04-17T01:25:12Z")

</div>

I tried. I got back a reply:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/3/b3cbf3560cc0469b21ca50339a298efb61bdec1c.png)

status 200 is good... almost feels like it might have worked?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [16 June 2020 01:25 UTC](https://discourse.nodered.org/t/post-form-unable-to-parse-json-body/24988/5 "2020-06-16T01:25:17Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
