Matt
Matt

Reputation: 79

with Python, how can I save a json dumps as a CouchDB document?

Given the following example data :

[
    "this",
    1000,
    {
        "that": 1
    }
]

(which is valid json according to jsonlint.com)

data=json.loads('["this",1000,{"that":1}]')

when I try to save that structure to CouchDB, it generates an error.

db['testdoc']=json.dumps(data)
ServerError: (400, ('bad_request', 'Document must be a JSON object'))

How then, should I save that type of structure?

I'm clearly missing something important.

Upvotes: 0

Views: 2627

Answers (1)

Laurent LAPORTE
Laurent LAPORTE

Reputation: 22952

According to this site: https://wiki.apache.org/couchdb/Getting_started_with_Python, simply write:

data = json.loads('["this",1000,{"that":1}]')
db['testdoc'] = data

Here, data is a classic Python list.

Upvotes: 1

Related Questions