question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

json: true sends "true" as request body no matter what

See original GitHub issue
xhr({body: {foo: 'bar'}, json: true})

will post true as request body.

It even sends false as request body if passing json: false.

According to request docs, the json flag is only used as a modifier to body:

json - sets body to JSON representation of value and adds Content-type: application/json header. Additionally, parses the response body as JSON. (https://github.com/request/request/blob/master/README.md#requestoptions-callback)

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
wesleytoddcommented, Nov 10, 2016

Hey, sorry if this is late to the party, or if I missed anything somewhere in #136, but it seems to me like this not working is a bug in the current branch that can be fixed before a major version bump. Something like this could fix it until #135 goes through:

body = JSON.stringify(options.json === true ? body : options.json)

This bug blocks a bunch of legitimate use cases (body-less DELETE requests which expect json back, for example) in the 2.0 branch, and so I think holding up a release here is a mistake, but that is just my personal opinion.

I can submit the PR for this if it seems like a good change

0reactions
naugturcommented, Nov 20, 2016

merged, releasing 2.3.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

JSON Post request for boolean field sends false by default
When you are using libraries like lombok to generate getters and setters, don't add 'is' with the field name if the field type...
Read more >
Sending boolean as body for JSON request not working properly
Yes, not sending a body and having json: true works fine. Setting body: null is what causes the issue since what was previously...
Read more >
5.x API - Express.js
Enables or disables handling deflated (compressed) bodies; when disabled, deflated bodies are rejected. Boolean, true. limit, Controls the maximum request body ...
Read more >
Accepting Raw Request Body Content in ASP.NET Core API ...
I'm essentially doing the same thing as in the first request, except I'm not sending JSON content type but plain text.
Read more >
ansible.builtin.uri module – Interacts with webservices
The body of the http request/response to the web service. ... true. force_basic_auth. boolean. Force the sending of the Basic authentication header upon ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found