You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Andrew Woodcock <an...@gmail.com> on 2010/07/27 23:24:04 UTC

Curl giving “Invalid UTF-8 JSON” error from CouchDb although JSON is fine? Any ideas?


Hi there,

this is probably a real noob problem but I am experiencing an issue 
where whenever I try to create a document on CouchDB using curl, I get 
an "Invalid UTF-8 JSON" error. The example I am trying to use is 
actually from O'Reilly's book "CouchDB: The Definitive Guide" and I am 
pretty sure that I have tried it before and got it to work. Here's the 
command:

|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 exists and the username and password are correct. I 
have checked this with JSONLint and the JSON is valid and I am at a loss 
... presumably there is an issue with the CouchDB server itself but it 
appears to be running correctly ... any ideas? This is driving me nuts!

I am running CouchDB 0.11 on Windows 7. curl is installed and working 
correctly as far as I can tell. Sofa is working correctly and I can 
create documents via Sofa with no issues.

Thanks,

Andrew


Re: Curl giving “Invalid UTF-8 JSON” error from CouchDb although JSON is fine? Any ideas?

Posted by Andrew Woodcock <an...@gmail.com>.
  On 28/07/2010 08:52, Dave Cottlehuber wrote:
> Hi Andrew
>
> This is a windows thing regarding quoting - a real PITA. Unfortunately
> cmd.exe shell on windows doesn't parse this correctly.
> The rules for when escaping with a "" or a ^" or a \" are a bit vague
> but this works:
>
> C:\tmp>curl -X PUT
> http://@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"}
>
> C:\tmp>
>
> "basically you need to \"escape\" all \"quotes\" within your JSON"
>
> Is there any way we to get this updated in the online book?
>
> A+
> Dave
>
>
> On 28 July 2010 09:24, Andrew Woodcock<an...@gmail.com>  wrote:
>>
>> Hi there,
>>
>> this is probably a real noob problem but I am experiencing an issue where
>> whenever I try to create a document on CouchDB using curl, I get an "Invalid
>> UTF-8 JSON" error. The example I am trying to use is actually from
>> O'Reilly's book "CouchDB: The Definitive Guide" and I am pretty sure that I
>> have tried it before and got it to work. Here's the command:
>>
>> |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 exists and the username and password are correct. I have
>> checked this with JSONLint and the JSON is valid and I am at a loss ...
>> presumably there is an issue with the CouchDB server itself but it appears
>> to be running correctly ... any ideas? This is driving me nuts!
>>
>> I am running CouchDB 0.11 on Windows 7. curl is installed and working
>> correctly as far as I can tell. Sofa is working correctly and I can create
>> documents via Sofa with no issues.
>>
>> Thanks,
>>
>> Andrew
>>
>>
Thank you,

that worked.

Regards,

Andrew

Re: Curl giving “Invalid UTF-8 JSON” error from CouchDb although JSON is fine? Any ideas?

Posted by Dave Cottlehuber <da...@muse.net.nz>.
Hi Andrew

This is a windows thing regarding quoting - a real PITA. Unfortunately
cmd.exe shell on windows doesn't parse this correctly.
The rules for when escaping with a "" or a ^" or a \" are a bit vague
but this works:

C:\tmp>curl -X PUT
http://@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"}

C:\tmp>

"basically you need to \"escape\" all \"quotes\" within your JSON"

Is there any way we to get this updated in the online book?

A+
Dave


On 28 July 2010 09:24, Andrew Woodcock <an...@gmail.com> wrote:
>
>
> Hi there,
>
> this is probably a real noob problem but I am experiencing an issue where
> whenever I try to create a document on CouchDB using curl, I get an "Invalid
> UTF-8 JSON" error. The example I am trying to use is actually from
> O'Reilly's book "CouchDB: The Definitive Guide" and I am pretty sure that I
> have tried it before and got it to work. Here's the command:
>
> |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 exists and the username and password are correct. I have
> checked this with JSONLint and the JSON is valid and I am at a loss ...
> presumably there is an issue with the CouchDB server itself but it appears
> to be running correctly ... any ideas? This is driving me nuts!
>
> I am running CouchDB 0.11 on Windows 7. curl is installed and working
> correctly as far as I can tell. Sofa is working correctly and I can create
> documents via Sofa with no issues.
>
> Thanks,
>
> Andrew
>
>

Re: Curl giving “Invalid UTF-8 JSON” error from CouchDb although JSON is fine? Any ideas?

Posted by Andrew Woodcock <an...@gmail.com>.
  On 28/07/2010 07:24, Sebastian Cohnen wrote:
> Hey Andrew,
>
> I remember people on this ML having problems with escaping/quotes on windows which leads to this kind of error. You could try to save the document to foo.json and curl-X PUT http://username:password@127.0.0.1:5984/albums/6e1295ed6c29495e54cc05947f18c8af -d @foo.json
>
> Best
>
> Sebastian
>
> On 27.07.2010, at 23:24, Andrew Woodcock wrote:
>
>>
>> Hi there,
>>
>> this is probably a real noob problem but I am experiencing an issue where whenever I try to create a document on CouchDB using curl, I get an "Invalid UTF-8 JSON" error. The example I am trying to use is actually from O'Reilly's book "CouchDB: The Definitive Guide" and I am pretty sure that I have tried it before and got it to work. Here's the command:
>>
>> |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 exists and the username and password are correct. I have checked this with JSONLint and the JSON is valid and I am at a loss ... presumably there is an issue with the CouchDB server itself but it appears to be running correctly ... any ideas? This is driving me nuts!
>>
>> I am running CouchDB 0.11 on Windows 7. curl is installed and working correctly as far as I can tell. Sofa is working correctly and I can create documents via Sofa with no issues.
>>
>> Thanks,
>>
>> Andrew
>>
Thanks Sebastian,

I will give this a try.

Regards,

Andrew

Re: Curl giving “Invalid UTF-8 JSON” error from CouchDb although JSON is fine? Any ideas?

Posted by Andrew Woodcock <an...@gmail.com>.
  On 28/07/2010 07:24, Sebastian Cohnen wrote:
> Hey Andrew,
>
> I remember people on this ML having problems with escaping/quotes on windows which leads to this kind of error. You could try to save the document to foo.json and curl-X PUT http://username:password@127.0.0.1:5984/albums/6e1295ed6c29495e54cc05947f18c8af -d @foo.json
>
> Best
>
> Sebastian
>
> On 27.07.2010, at 23:24, Andrew Woodcock wrote:
>
>>
>> Hi there,
>>
>> this is probably a real noob problem but I am experiencing an issue where whenever I try to create a document on CouchDB using curl, I get an "Invalid UTF-8 JSON" error. The example I am trying to use is actually from O'Reilly's book "CouchDB: The Definitive Guide" and I am pretty sure that I have tried it before and got it to work. Here's the command:
>>
>> |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 exists and the username and password are correct. I have checked this with JSONLint and the JSON is valid and I am at a loss ... presumably there is an issue with the CouchDB server itself but it appears to be running correctly ... any ideas? This is driving me nuts!
>>
>> I am running CouchDB 0.11 on Windows 7. curl is installed and working correctly as far as I can tell. Sofa is working correctly and I can create documents via Sofa with no issues.
>>
>> Thanks,
>>
>> Andrew
>>
Fantastic! Thank you! That must be about the only combination of 
escaping I hadn't tried :) and I can confirm that it worked perfectly.

I can stop ripping my hair out now ...

Regards,

Andrew

Re: Curl giving “Invalid UTF-8 JSON” error from CouchDb although JSON is fine? Any ideas?

Posted by Sebastian Cohnen <se...@googlemail.com>.
Hey Andrew,

I remember people on this ML having problems with escaping/quotes on windows which leads to this kind of error. You could try to save the document to foo.json and curl-X PUT http://username:password@127.0.0.1:5984/albums/6e1295ed6c29495e54cc05947f18c8af -d @foo.json

Best

Sebastian

On 27.07.2010, at 23:24, Andrew Woodcock wrote:

> 
> 
> Hi there,
> 
> this is probably a real noob problem but I am experiencing an issue where whenever I try to create a document on CouchDB using curl, I get an "Invalid UTF-8 JSON" error. The example I am trying to use is actually from O'Reilly's book "CouchDB: The Definitive Guide" and I am pretty sure that I have tried it before and got it to work. Here's the command:
> 
> |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 exists and the username and password are correct. I have checked this with JSONLint and the JSON is valid and I am at a loss ... presumably there is an issue with the CouchDB server itself but it appears to be running correctly ... any ideas? This is driving me nuts!
> 
> I am running CouchDB 0.11 on Windows 7. curl is installed and working correctly as far as I can tell. Sofa is working correctly and I can create documents via Sofa with no issues.
> 
> Thanks,
> 
> Andrew
>