#36139 closed New feature (wontfix)
Allow expressing JSONObject keys dynamically, as well as explicit pair-values
Reported by: | john-parton | Owned by: | john-parton |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
Currently there is no way to build a JSON object in the database using the JSONObject function where the keys are anything but static keys.
This is not a limitation of any of the backends that support JSON objects.
If you could specify the items of a JSONObject positionally, you get the benefit of being able to construct objects with non-static keys.
As an example esoteric usage, if you're trying to get the database to emit valid objects for the Elasticsearch DSL, you would almost certainly need to be able to build objects with non-static keys.
For example https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-term-query.html
The key "user.id" refers to a field in elastic.
See some discussion here: https://github.com/django/django/pull/19097#issuecomment-2611270246
I'll throw together a patch.
Change History (8)
comment:1 by , 4 weeks ago
comment:2 by , 4 weeks ago
Has patch: | set |
---|
comment:3 by , 4 weeks ago
Owner: | set to |
---|---|
Status: | new → assigned |
comment:4 by , 4 weeks ago
Resolution: | → wontfix |
---|---|
Status: | assigned → closed |
Hi John, thank you for raising this!
As this is a new feature request, can you propose and discuss the idea on the Django Forum to gain consensus?
I can see that Simon said he felt this was a less useful feature than for JSONArray
(refs #36134), so we should confirm that there is a need for this feature from the community before working on it.
I'll close the ticket for now, but if the community agrees with the proposal, please return to this ticket and reference the forum discussion so we can re-open it. For more information, please refer to the documented guidelines for requesting features.
comment:5 by , 3 weeks ago
Note that Simon said he felt that ON NULL ABSENT
for JSONObject was less useful. This doesn't directly enable that functionality, as I mostly agree.
This is specifically for building JSON objects where keys are dynamic expressions, which Simon didn't comment on.
comment:6 by , 3 weeks ago
comment:7 by , 3 weeks ago
Description: | modified (diff) |
---|
comment:8 by , 3 weeks ago
I've modified the description of this ticket to remove any references to ABSENT ON NULL
and to remove any reasoning about that. Just straightforward describe just this one feature.
Pull request/patch here: https://github.com/django/django/pull/19101
Not too bad for the actual code change, just a few lines. Several tests added and expanded the
Usage
section of the documentation sufficiently to cover the various use cases.