Questions tagged [jsonfield]
28 questions
11
votes
1 answer
Django 3.1+: (fields.E180) SQLite does not support JSONFields
I have created a Django project with the new JSONField announced in Django 3.1, which supports all databases.
I have successfully used this field on a linux machine, but running python manage.py migrate with the same project on Windows fails with…

Udi
- 29,222
- 9
- 96
- 129
3
votes
1 answer
Django getting values from postgres JSON field
I have a simple model like:
class MyModel(models.Model):
data = JSONField()
The JSONField data is in the following structure:
{
"name": "Brian",
"skills": [
{"id": 4, "name": "First aid"},
{"id": 5, "name": "Second aid"}
…

Tom Hamilton Stubber
- 729
- 1
- 5
- 15
2
votes
0 answers
django_filter custom Filter for jsonfield howto populate filter dropdown?
I am working on a django_filter for data stored in a jsonfield (no, for now I want to keep it this way).
payload = models.JSONField()
I developed a custom filter to emulate the behavior of athe filter for normal fields. I've got it almost…

moin moin
- 2,263
- 5
- 32
- 51
1
vote
1 answer
Aggregate sum of values from Django JSONField
Consider I have a simple model setup with JSONField
from django.db import models
import random
def simple_json_callable():
return {"amount": random.randint(1, 100)}
def nested_json_callable():
data = {
"l1": {
"l2":…

JPG
- 82,442
- 19
- 127
- 206
1
vote
1 answer
Querying within a list of dicts within a Django model JSONField
I'm trying to query an element within a list of dicts in a Django JSONField. I can find similar questions to mine but not one that covers what I'm trying to do. It seems like it should be simple and fairly common so I suspect I'm missing something…

Ludo
- 2,739
- 2
- 28
- 42
1
vote
1 answer
The JSON field uses to decide the value for another JSON field in Jolt
Let say we have on JSON
{
"payments": [
{
"paymentId": "16493256102836651255",
"amount": 9.26,
"cardType": "DISC",
"transactionType": "PAYPAL"
}
]
}
expected :
{
"payment": [
{
"paymentId":…

user3459251
- 11
- 2
1
vote
1 answer
How to query and update nested JSON data in Django
I have below class defined to do statistics for voting system.
class FormPage(AbstractForm):
submission_stats = models.JSONField(null=True, editable=False)
Now, I have submission_stats in below format:
[
{
"id":4,
…

Yan Tian
- 377
- 3
- 11
1
vote
1 answer
How to query a Django JSONField with a nested dictionary?
I'm using Django 3.2.3 / Python 3.7.8 / PostgreSQL 12.3
models.py
class Booking(models.Model):
reference = models.CharField(max_length=15, unique=True)
services = models.JSONField()
The services structure is:
{
'1':{
'id': 3,
…

Rk..
- 753
- 1
- 10
- 27
1
vote
1 answer
Django jsonfield, is it possible to filter with json array value length?
Suppose I have a jsonfield with data
from django.contrib.postgres.fields import JSONField
class Foo(models.Model):
json_field = JSONField(default=dict)
json_field = {
'bar': [1,2,3,4]
}
I'd like to filter data where bar has array length…

eugene
- 39,839
- 68
- 255
- 489
0
votes
1 answer
How to parse serialized json in Postgresql?
I have a data like below and I would like to get a value of sub_key1:
'{"key_1":"val_1", "key_2":"{\"sub_key1\":\"sub_val1\", \"sub_key2\":\"sub_val2\"}"}'
If I run below query, it works fine and gets me the value of key_2.
SELECT…

Arch Desai
- 191
- 1
- 8
0
votes
0 answers
fastap how to filter sqlalchemyi query by json field
i am trying to filter by json-filed in fastapi using sqlalchemy
class Database_Model(Base):
tablename = "database_model"
data = Column(JSON, nullable=False)
@router.get("/test/")
def test(
db: Session = Depends(get_db)
):
return (
…

Rashid
- 1
0
votes
0 answers
Assign a type to JSONField in Django
I'm using a property of type JSONField in my model:
from django.db import models
class MyClass(models.Model):
variables = models.JSONField()
I want to avoid as much as possible using strings to access variables properties, is there any way to…

Bagbyte
- 845
- 2
- 18
- 34
0
votes
1 answer
Doing polymorphic model, what's the best approach?
I'm trying to upscale a project that originally was used by an area to assign reports to their respective departments.
Those reports I want them to be tasks, to broaden the spectrum of use to all of the organization.
Originally, I was using separate…

LCD_
- 3
- 2
0
votes
1 answer
Django - Merge jsonfield's new data with the old data
So let's assume that I have a model with a jsonfield while using Postgres as a database
class Baum(models.Model):
myjson = models.JSONField(...)
Now I'd like to know what would be the best way to edit the model fields saving…

mika
- 86
- 8
0
votes
2 answers
Restructure json data
I have a JSON with following structure:
{
"id": 2,
"image_id": 2,
"segmentation": [
[
913.0,
659.5,
895.0,
],
[
658.5,
875.0,
652.5,
…

Deamoon
- 3
- 4