I
I
Invoker3222020-02-02 09:21:29
Django
Invoker322, 2020-02-02 09:21:29

How to find out what is in json and how to parse it and save only the necessary information?

Good morning. I'm stuck on this, let's say I send information to the rest api, not even from the front, but for example, there is a request from another site in general, and there is a lot of information in this request, how can I check what kind of information is there and how to save only what is necessary to the database ? If everything is clear with the front, I'm waiting for a login and password, then I have a model with a login and password and serialization for this, then I need help here. I don’t know how to check the data in the request and how to parse it, but I won’t need to write to describe the model for all this huge data array? I only need 2-3 fields. Thank you in advance.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dr. Bacon, 2020-02-02
@bacon

Parse json from string - json.loads. How to work with it further, you need to learn the basics of python, or rather, work with list and dict data structures,

D
Dirlandets, 2020-02-02
@Dirlandets

Use standard Python tools like the json library
Here is a good article on how to deal with json.
The scheme of work is as follows. You get a server response or whatever you have there. You turn it into a python object and do all the necessary manipulations.

A
Alexander, 2020-02-04
@cashncarry

I do like this:

r = requests.get(url, params)
r_json = r.json()
r_json['some_field']  # если список то пройтись циклом for i in r_json

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question