-
Notifications
You must be signed in to change notification settings - Fork 237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error: Invalid Json #130
Comments
Hi, Can you share a snippet of code? Sorry for the long delay, but I was quite swamped these past months. :) |
Ping? |
I think my issue is reletaed to this one: I had some code that used to work and stopped working recently. I was trying to save a list of documents in bulk to couchdb. You do this by POSTing a document to /_bulk_docs?include_docs=true So I used to do something like this: bulk = { "all-or-nothing": true, "docs": myArrayOfDocuments } bulkString = JSON.stringify( bulk ) needle.post( fullUrl, bulkString, bulkRequestOptions, cb ) And just today it seems I suddenly needed to do the following to make it work: bulk = { "all-or-nothing": true, "docs": myArrayOfDocuments } needle.post( fullUrl, bulk, bulkRequestOptions, cb ) In this case, I did have the header set to "Content-Type': "application/json" What surprises me is that it stopped working with a string (this code has worked for more than a year), because I should be able to do my own stringifying and be sure that that is what will be sent. Now it feels as if my string is being tampered with afterwards. |
Needle did have some changes in the way data is fed to the request, but nothing major that should break anything. If you want to send an object as a JSON object, just pass the original object and set |
I'm not sure what the problem is, by the way. |
If you take a look at the tests in In your example above, what does bulkRequestOptions look like? That way I can try to replicate both cases and see what's different. |
You get an error of Invalid Json when you set your Content-Type to be application/json when doing needle.post.
If you don't set Content-Type at all, the post operation works.
Moving forward, needle shouldn't force Content-Type on an options object when it has been explicitly set by the User.
The text was updated successfully, but these errors were encountered: