andrewlocatelliwoodcock

Thoughts on Software

Curl returning “Invalid UTF-8 JSON” error from CouchDb on Windows although JSON is correct

leave a comment »


I have been playing around with CouchDB for a while now but early on hit a problem with some of the examples in O’Reilly’s “CouchDB: The Definitive Guide”: Curl, when used on Windows, kept giving an “Invalid UTF-8 JSON” error even though the JSON itself was correct.

The example I was trying to use was taken from the O’Reilly book:

curl -X PUT http://username:password@127.0.0.1:5984/albums/6e1295ed6c29495e54cc05947f18c8af -d '{"title":"There is Nothing Left to Lose","artist":"Foo Fighters"}' 

The database albums existed and the username and password were correct … so what was going on? Turns out it was an issue with escaping quotes in the cmd shell in Windows … Basically, use double instead of single quotes for the JSON string being posted and escape all quotes within that string with \”:

curl -X PUT http://username:password@127.0.0.1:5984/albums/6e1295ed6c29495e54cc05947f18c8af -d "{\"title\":\"There is Nothing Left to Lose\",\"artist\":\"Foo Fighters\"}" {"ok":true,"id":"6e1295ed6c29495e54cc05947f18c8af","rev":"1-4b39c2971c9ad54cb37e08fa02fec636"}

Obviously, replace username and password values with your actual user name and password but this example will work.

Written by andrewlocatelliwoodcock

May 11, 2011 at 21:57

Posted in CouchDb

Tagged with ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: