0

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.

Matt
  • 79
  • 2
  • 9
  • You are passing a string, couchdb-python does the conversion to JSON for you. All you need to do is make sure your python object is serializable. – Hans May 04 '14 at 21:10
  • I see, so a string is not serializable? I notice I can use `db['testdoc']={'data':data}` – Matt May 08 '14 at 12:26

1 Answers1

1

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.

Laurent LAPORTE
  • 21,958
  • 6
  • 58
  • 103