# Handling German Umlaute when writing to JSONField to database

**URL:** <https://forum.djangoproject.com/t/handling-german-umlaute-when-writing-to-jsonfield-to-database/22467>\
**Category:** Forms & APIs\
**Created:** [July 21, 2023, 10:38pm UTC](https://forum.djangoproject.com/t/handling-german-umlaute-when-writing-to-jsonfield-to-database/22467 "2023-07-21T22:38:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![xtlc](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/xtlc/32/3887_2.png) [@xtlc](https://forum.djangoproject.com/u/xtlc)\
**Post date:** [July 21, 2023, 10:38pm UTC](https://forum.djangoproject.com/t/handling-german-umlaute-when-writing-to-jsonfield-to-database/22467/1 "2023-07-21T22:38:45Z")

</div>

I am using an existing database which is encoded in `utf8mb4_general_ci`.  
The problem I am facing occurs with postgres and SQLite:

my database:

```auto
class Product(models.Model):
    data = models.JSONField()
    number = models.PositiveIntegerField()

```

when writing the word `Gemüse` to the db, I can see this entry in SQLite:

```auto
{"name": "Gem\u00fcse"}

```

This is a problem, because I have a search function on the site, that selects sets from the database like this:

```auto
def get_queryset(self):
        qs = super().get_queryset().order_by("number")
        search = self.request.GET.get("search")
        if search:
            qs = qs.filter(Q(data__icontains = search) | Q(number__icontains = search))
        return qs

```

and obviously searching for `Gemüse` yields nothing.  
I am asking myself what my best way forward is here:

- Should I try to save my data to the database the same way as now and modify my search so I can find `Gemüse` also as `Gem\u00fcse`? How would I do that?
- Is there a way to transform my database from utf8mb4\_general\_ci to another encoding so I can get rid of the problem this way? This is only important for the postgres part, the SQLite ist just for testing
- Could I already implement something on the template level to make sure this problem never comes back?

---

<div class="post-metadata">

**Author:** ![xtlc](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/xtlc/32/3887_2.png) [@xtlc](https://forum.djangoproject.com/u/xtlc)\
**Post date:** [July 22, 2023, 7:34am UTC](https://forum.djangoproject.com/t/handling-german-umlaute-when-writing-to-jsonfield-to-database/22467/2 "2023-07-22T07:34:13Z")

</div>

Maybe a little bit of an Add-on as this is not the first trouble I ran into:

Before the update from django 3 → 4 I used a customized JSONField:

```auto
class CustomJSONField(models.JSONField):
    def get_prep_value(self, value):
        if value is None:
            return value
        return json.dumps(value, ensure_ascii = False)

class Product(models.Model):
    data = CustomJSONField()

```

But after the update (and a server update as well) I got all my JSON data into the database like this: `"{\"name\": \"Gem\u00fcse\"}"`. So I thought I can maybe change that back to just using `JSONField` but in testing the Umlaute-Error occured (but I got rid of the escaped quotes and got a valid JSON and not a string).
