4
votes

I have an attribute that I'm storing as a JSON object, like so:

content  = ndb.JsonProperty()

When I do this, I get this error:

   line 1614, in _to_base_type
    return json.dumps(value, 2)
AttributeError: 'module' object has no attribute 'dumps'

inside the ndb model class.

As a ndb.TextProperty it works properly. Maybe I'm sending the JSON wrong, this is the JSON object I'm sending:

{posttext: "What is your earliest memory of WWII?", linkdata: ""}
2

2 Answers

11
votes

Do you perhaps have a module named 'json.py' or a package named 'json' in your app? That would override the json module that ndb is trying to import. The solution is to pick a different name for that module or package.

1
votes

What you're describing works fine when I try it:

from google.appengine.ext import ndb
class TestModel(ndb.Model):
  foo = ndb.JsonProperty()
t = TestModel(foo={"posttext": "What is your earliest memory of WWII?", "linkdata": ""})
t.put()
Key('TestModel', 7001)

Can you go into more detail about exactly how you're doing this? How does it differ from the snippet above?