import json file to couch db- import json file to couch db- json json

import json file to couch db-


Starting from @Millhouse answer but with multiple docs in my file I used

cat myFile.json | lwp-request -m POST -sS "http://localhost/dbname/_bulk_docs" -c "application/json" 

POST is an alias of lwp-request but POST doesn't seem to work on debian. If you use lwp-request you need to set the method with -m as above.

The trailing _bulk_docs allows multiple documents to be uploaded at once.

http://wiki.apache.org/couchdb/HTTP_Bulk_Document_API


If you are on Linux, You could write a quick shell script to POST the contents of valid json files to Couch.

To test couch I did something like this:

cat myFile.json | POST -sS "http://myDB.couchone.com/testDB" -c "application/json"

myFile.json has the json contents I wanted to import into the database.

Another alternative, if you don't like command line or aren't using Linux, and prefer a gui, you can use a tool like RESTClient


Probably a bit late to answer. But If you can use Python than you can use the couchdb module to do so:

import couchdbimport jsoncouch = couchdb.Server(<your server url>)db = couch[<your db name>]with open(<your file name>) as jsonfile:    for row in jsonfile:        db_entry = json.load(row)        db.save(db_entry)

I created the python script to do that(As I could not find one on Internet).

The full script is here: :

http://bitbucket.org/tdatta/tools/src/

(name --> jsonDb_to_Couch.py)

If you download the full repo and:

  1. Text replace all the "_id" in json files to "id"

  2. Run make load_dbs

It would create 4 databases in your local couch installation

Hope that helps newbies (like me)