1

I have a JSONField in my model and I wasn't able to clean the initial import on my resource so the data imported were treated as strings instead of lists. When I export the data it looks like this:

enter image description here

The ones below are the previous data from the initial import-export without a custom JSONWidget. The ones above are the data that was cleaned.

How can I then fix the current JSONField with the string and convert it to a list?

Prosy Arceno
  • 2,616
  • 1
  • 8
  • 32

1 Answers1

3

Presumably you want to clean the values in the database, so that they are standardised to empty list. If so, there are a few ways you could do this:

  • A straight UPDATE command via SQL (example)
  • If you can run ./manage.py shell you should be able to filter the entries and correct the data.
  • If you can run django-admin commands, write a script which filters and corrects the data, then use the django-extensions runscript command.
  • Create a data migration

Please correct me if I have misunderstood what you are aiming to do.

Matthew Hegarty
  • 3,791
  • 2
  • 27
  • 42
  • Thanks, haven't tried any but I bet all these will work. However, I remembered I can just bulk update with the django-import-export to clean all the values. I'll accept it still because you did help me in cleaning the data on one of my previous questions. – Prosy Arceno Nov 10 '21 at 18:46