tags:

views:

337

answers:

3

If I have a json file that looks something like this:

{"name":"bob","hi":"hello"}
{"name":"hello","hi":"bye"}

Is there an option to import this into couchdb?

+2  A: 

that's not valid JSON

Javier
right so if i have a bunch of json objects is there a way to import it?
i have to go one by one and import them individually right?
+2  A: 

As noted, that is not a valid JSON object or couchdb database. I can see two plausible designs. One is to have a different couchdb document for each row, and the other is to use an array like:

{
  "people": 
   [
      {
        "name":"bob",
        "hi":"hello"
      },
      { 
        "name":"hello",
        "hi":"bye"
      }
   ]
}
Matthew Flaschen
A: 

http://github.com/zaphar/db-couchdb-schema/tree/master

My DB::CouchDB::Schema module has a script to help with loading a series of documents into a CouchDB Database. The couch_schema_tool.pl script accepts a file as an argument and loads all the documents in that file into the database. Just put each document into an array like so:

[ {"name":"bob","hi":"hello"}, {"name":"hello","hi":"bye"} ]

It will load them into the database for you. Small caveat though I haven't tested my latest code against CouchDB's latest so if you use it and it breaks then let me know. I probably have to change something to fit the new API changes.

Jeremy

Jeremy Wall