Ability to specify keys for JSONObject using arbitrary expressions

Yes, it could be a project thing.

I’ve got a version of the code in my project which functions as described.

However, it has to either subclass the existing JSONObject function (annoying OO caveats) or copy/paste Django code to function (DRY/maintainability violation).

It turns out that there is some very annoying inconsistencies between the various DB backends.

Having it an official/included part of Django means it’s more likely to work automatically and correctly when using a 3rd party backend.

Regarding an actual example of when it might be useful, that’s where I’m less sure.

Let’s say you have an EAV table or something similar.

class Attribute(models.Model):
key = models.CharField()
value = models.CharField()

And an entry of “color”, “Red”

You might want the ability to produce documents like {“color”: “Red”}

1 Like