1

I have a JSONField which seems to be successfully storing a JSON as a string in my database.

How do I retrieve this data as a dictionary?

class Package:
    node = JSONField(null=True, blank=True)

packageInstance = Package.objects.get(id=packageId)
print(packageInstance.node)
Ralf
  • 16,086
  • 4
  • 44
  • 68
GeneralBear
  • 1,011
  • 3
  • 11
  • 35

1 Answers1

2

Your packageInstance.node is a python dictionary already

The official docs verify it too https://docs.djangoproject.com/en/2.0/ref/contrib/postgres/fields/#jsonfield

Simply put Django converts the json string to python dict automatically when you work with JSONField like you showed.

Bob
  • 5,809
  • 5
  • 36
  • 53