CouchDB cURL Windows Command Line Invalid JSON CouchDB cURL Windows Command Line Invalid JSON json json

CouchDB cURL Windows Command Line Invalid JSON


The answer is related to the formatting of the JSON string on the command line. Even though it is proper JSON when you type it, the command line, it seems, must reformat it before sending it.(Maybe someone else can explain why it does this in more detail.) To fix this you need to escape your quotations in the command line like so:

curl -H "Content-Type: application/json" -X POST "http://127.0.0.1:5984/test" -d {"""valid""":"""json"""}

See the extra quotation marks? This should work and return "ok:true" with an id and revision number.


You have to quote also the whole statement to support spaces like: -d "{\"title\":\"There is Nothing Left to Lose\" , \"artist\":\"Foo Fighters\"}"