F
F
Friend2020-01-24 05:49:21
Django
Friend, 2020-01-24 05:49:21

How to upload json to Django database using loaddata?

I came across a task related to loading data from json into Django db via manage.py loaddata.
The problem is that the data is in this format:

[
  {
    "id": 1,
    "first_name": "Gena",
    "last_name": "Bukin",
    "email": "[email protected]",
    "gender": "Male",
    "ip_address": "17.13.19.31"
  },
  {
    "id": 2,
    "first_name": "Anton",
    "last_name": "Drakon",
    "email": "[email protected]",
    "gender": "Male",
    "ip_address": "15.25.235.175"
  }
]

I can't figure out why this format and not this one:
[
  {
    "model": "myapp.person",
    "pk": 1,
    "fields": {
      "first_name": "John",
      "last_name": "Lennon"
    }
  },
  {
    "model": "myapp.person",
    "pk": 2,
    "fields": {
      "first_name": "Paul",
      "last_name": "McCartney"
    }
  }
]

Is this a bug in the job or is it still possible to load the data in that format via manage.py loaddata ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Shubin, 2020-01-24
@idegree

How about writing a script to convert one JSON format to another and then load it via manage.py loaddata?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question