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

StackOverflow https://stackoverflow.com/questions/19455256

  •  01-07-2022
  •  | 
  •  

Question

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.

Was it helpful?

Solution

CouchDB has a bulk documents API;

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top