# How to make Django modifiy JSONField value effictively

**URL:** <https://forum.djangoproject.com/t/how-to-make-django-modifiy-jsonfield-value-effictively/8937>\
**Category:** ORM\
**Created:** [July 25, 2021, 12:22pm UTC](https://forum.djangoproject.com/t/how-to-make-django-modifiy-jsonfield-value-effictively/8937 "2021-07-25T12:22:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jcyrss](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/jcyrss/32/5271_2.png) [@jcyrss](https://forum.djangoproject.com/u/jcyrss)\
**Post date:** [July 25, 2021, 12:22pm UTC](https://forum.djangoproject.com/t/how-to-make-django-modifiy-jsonfield-value-effictively/8937/1 "2021-07-25T12:22:39Z")

</div>

With MySQL8.0.25 as database backend, I make Django ORM to update the following JSONField value

```json
{
  "01-task1": {"data":"huge data here"}
}

```

just add a new element , `"02-testing": {}`

but I got the following sql log

```sql
(0.000) UPDATE `by_jsontree_store1` SET `store_type` = 1, `user_id` = 2, `data` = '{\"01-task1\": {\"data\": \"huge data here\"}, \"02-testing\": {}}' 

WHERE `by_jsontree_store1`.`id` = 1; args=(1, 2, '{"01-task1": {"data": "huge data here"}, "02-testing": {}}', 1)

```

It looks like Django write the whole content of that JSONField.

Imaging if the original content is huge, like 100MB, what could happen.

Could Django update JSON field partially, just update what it need to?

Or for time being, Django can not convert ORM JSONField updating to to JSON\_SET, JSON\_REPLACE and JSON\_REMOVE in MYSQL8.0 ？ So we have to write raw sql to do that?

---

<div class="post-metadata">

**Author:** ![felixxm](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/felixxm/32/2479_2.png) [@felixxm](https://forum.djangoproject.com/u/felixxm)\
**Post date:** [July 26, 2021, 5:45am UTC](https://forum.djangoproject.com/t/how-to-make-django-modifiy-jsonfield-value-effictively/8937/2 "2021-07-26T05:45:45Z")

</div>

This is still an open issue, see [#32519 (Add support for using key and path transforms in update() for JSONFields.) – Django](https://code.djangoproject.com/ticket/32519).

---

<div class="post-metadata">

**Author:** ![allen-munsch](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/allen-munsch/32/1627_2.png) [@allen-munsch](https://forum.djangoproject.com/u/allen-munsch)\
**Post date:** [February 12, 2022, 11:24pm UTC](https://forum.djangoproject.com/t/how-to-make-django-modifiy-jsonfield-value-effictively/8937/3 "2022-02-12T23:24:06Z")

</div>

I know you were using MYSQL, but if you know the raw sql you might be able to stitch something together in the mean time similar to:

- [python - How to Django ORM update() multiple values nested inside a JSONField? - Stack Overflow](https://stackoverflow.com/questions/68620977/how-to-django-orm-update-multiple-values-nested-inside-a-jsonfield)
- [#32179 (Add JSONObject Func) – Django](https://code.djangoproject.com/ticket/32179)
- [PostgreSQL: Documentation: 14: 9.16.&nbsp;JSON Functions and Operators](https://www.postgresql.org/docs/current/functions-json.html)

Although, I’m not sure about the internals, and what kind of memory requirements would be needed to make it happen. Might be worth looking into for the time being.
