# Error decoding lambda response: json / deploying a function

**URL:** <https://answers.netlify.com/t/error-decoding-lambda-response-json-deploying-a-function/2425>\
**Category:** Support\
**Tags:** lambda-functions\
**Created:** [July 30, 2019, 2:47pm UTC](https://answers.netlify.com/t/error-decoding-lambda-response-json-deploying-a-function/2425 "2019-07-30T14:47:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![BrianSHenderson](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/brianshenderson/32/2087_2.png) [@BrianSHenderson](https://answers.netlify.com/u/BrianSHenderson)\
**Post date:** [July 30, 2019, 2:47pm UTC](https://answers.netlify.com/t/error-decoding-lambda-response-json-deploying-a-function/2425/1 "2019-07-30T14:47:57Z")

</div>

I have an issue when I try and deploy my Netlify functions to live, I receive this error message (although not when run locally).

> error decoding lambda response: json: cannot unmarshal bool into Go value of type string.

Is this linked to returning:  
exports.retData = oBody =\> {  
console.log(‘retData’, oBody)  
return {  
statusCode: 200,  
headers: {  
“Access-Control-Allow-Origin”: “\*”,  
“Access-Control-Allow-Methods”: “GET,POST,DELETE”,  
“Access-Control-Allow-Headers”:  
“Access-Control-Allow-Headers, Origin, Accept, Authorization, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers”  
},  
body: JSON.stringify(oBody)  
};  
};

---

<div class="post-metadata">

**Author:** ![alexrussell](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/alexrussell/32/2018_2.png) [@alexrussell](https://answers.netlify.com/u/alexrussell)\
**Post date:** [July 30, 2019, 4:36pm UTC](https://answers.netlify.com/t/error-decoding-lambda-response-json-deploying-a-function/2425/2 "2019-07-30T16:36:02Z")

</div>

At a guess, `oBody` is a bare `true` or `false` (whether on purpose as designed or due to a fault), but the thing that parses your return object (presumably something written in Go?) expects `body` to be a string (which is not unreasonable for an HTTP response).

---

<div class="post-metadata">

**Author:** ![Dennis](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/dennis/32/34_2.png) [@Dennis](https://answers.netlify.com/u/Dennis)\
**Post date:** [August 2, 2019, 8:51am UTC](https://answers.netlify.com/t/error-decoding-lambda-response-json-deploying-a-function/2425/4 "2019-08-02T08:51:59Z")

</div>

Yes, @alexrussell, that’s correct. @BrianSHenderson, that error from our system is typically seen when the body you are returning is not a valid stringified JSON string. Can you share what the value of `oBody` is? It’ll need to be a JSON object and not just a boolean as alex also suspects.

---

<div class="post-metadata">

**Author:** ![question\_asker](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/question_asker/32/11552_2.png) [@question\_asker](https://answers.netlify.com/u/question_asker)\
**Post date:** [June 22, 2020, 9:21pm UTC](https://answers.netlify.com/t/error-decoding-lambda-response-json-deploying-a-function/2425/5 "2020-06-22T21:21:29Z")

</div>

**Edit: solved! This stackoverflow answer was the key: [Revisions to Netlify NodeJS Function always returns 'Response to preflight request doesn't pass' - Stack Overflow](https://stackoverflow.com/posts/54117714/revisions)**

Summary: headers must be strings. I had:

`'Access-Control-Allow-Credentials': true`

It should have been:

`'Access-Control-Allow-Credentials': 'true'`

@Netlify this could really use some documentation.

* * *

I’m experiencing the same problem while returning a Stripe API response. I have no code written in GO at all.

The function works perfectly on local, but fails to return parsable JSON (or any plain text that looks like an object) when running on Netlify.

Logging on Netlify shows the function should be returning the following object, but it’s not:

```
{
  id: 'cs_live_foo_123,
  object: 'checkout.session',
  billing_address_collection: null,
  cancel_url: 'https://domain.com/pricing?status=cancel',
  client_reference_id: 'abc123',
  customer: null,
  customer_email: 'foo.bar@domain.com',
  livemode: true,
  locale: null,
  metadata: { planChosen: '{"plan":"lite","interval":"annual"}' },
  mode: 'subscription',
  payment_intent: null,
  payment_method_types: ['card'],
  setup_intent: null,
  shipping: null,
  shipping_address_collection: null,
  submit_type: null,
  subscription: null,
  success_url: 'https://domain.com/checkout?status=true&newPlan=lite'
}

```

I have also tried returning a simpler object:

`{ id: 'foo'}`

Same result.

My Netlify function response function includes a `JSON.stringify()`:

```
const respond = fulfillmentText => {
  console.log("about to stringify fullfillment text", fulfillmentText)
  return {
    statusCode: 200,
    body: JSON.stringify(fulfillmentText),
    headers: {
      'Access-Control-Allow-Credentials': true,
      'Access-Control-Allow-Origin': '*',
      'Content-Type': 'application/json',
    },
  }
}

```

---

<div class="post-metadata">

**Author:** ![jen](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/jen/32/6044_2.png) [@jen](https://answers.netlify.com/u/jen)\
**Post date:** [June 25, 2020, 12:20am UTC](https://answers.netlify.com/t/error-decoding-lambda-response-json-deploying-a-function/2425/7 "2020-06-25T00:20:10Z")

</div>

Thanks for sharing how you fixed this. We have seen other reports of this ([Function started responding with 502s overnight](https://answers.netlify.com/t/function-started-responding-with-502s-overnight/12683)), so I will file an issue for our Docs team and if there’s an update, we’ll report back here.

---

<div class="post-metadata">

**Author:** ![jen](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/jen/32/6044_2.png) [@jen](https://answers.netlify.com/u/jen)\
**Post date:** [July 2, 2020, 9:28pm UTC](https://answers.netlify.com/t/error-decoding-lambda-response-json-deploying-a-function/2425/8 "2020-07-02T21:28:43Z")

</div>

Update on this: we recently rolled out a change so that we’ll accept both integers and boolean values as header values 🎉
