views:

215

answers:

2

Question...I am trying to add data to CouchDB via the _bulk_docs API. For the most part I have this working, but any JSON value that contains a special character (e.g. certain Spanish or French characters exist in my data) results in an "invalid JSON" error given by CouchDB, and the data is rejected.

I'm not sure what I need to set in order to get this to work. Any suggestions? CouchDB seems to get the data properly (at least it looks correct in its log file), but it is not processed unless I remove the special chars.

A: 

content-type should be application/json, not test/plain

I'm not familiar with your JSON parser but make sure it's utf-8, just because your http client library is set to utf-8 doesn't mean your json serializer is outputing unicode.

mikeal
A: 

I'd try to debug the problem doing something like this:

  1. install on your machine a packet sniffer that understands http (e.g. wireshark) and launch it capturing packages sent to port 5984
  2. Create documents using curl from the command line:

    curl -X POST [email protected] http://localhost:6984/testdb/_bulk_docs

    where test.js contains some documents with special characters. And see if this works as expected.

  3. do the same with the java library and see the differences in http headers and request body in the 2 cases.

NOTE: curl by default should send the data with content-type: application/x-www-form-urlencoded and this might be the problem, but check the headers because I'm not sure.

Hope this can help you.

filippo
Thanks! This was all very helpful...it is now working. JQuery-based client web app to/from Jetty/Cometd, CouchDB, and Jackson are all talking :)
nkp