Search code examples
jsoncouchdbcloudant

How to save multiple JSON objects into couchdb? or Why does couchdb not accept outer brackets in JSON?


I'm trying to save this to a Cloudant database:

[
{
    "_id": "document_one",
    "heynow": [
        {
            "Name": "one",
            "Duration": 2,
            "DurationUnit": "Hours"
        },
        {
            "Name": "two",
            "Duration": 40,
            "DurationUnit": "Minutes"
        }
    ]
},
{
    "_id": "document_two",
    "heynow": [
        {
            "Name": "three",
            "Duration": 2,
            "DurationUnit": "Hours"
        },
        {
            "Name": "four",
            "Duration": 40,
            "DurationUnit": "Minutes"
        }
    ]
}
]

But apparently it doesn't like the outer brackets because it's telling me:

"error":"bad_request","reason":"Document must be a JSON object"

JSONLint says it's valid, so I guess I'm asking if anyone knows how to format this so it can be entered into a Couchdb because the outer brackets seem to be causing problems.


Solution

  • CouchDB has a bulk documents API;

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