A
A
Alixperio2018-11-20 18:43:46
Python
Alixperio, 2018-11-20 18:43:46

How to parse json with nested categories using a recursive function and save it to the database?

Hey!
Give advice or a source of information that will help to understand this issue!
How to parse json with categories and multiple subcategories in them using a recursive function in Python?
As a method of saving the tree in the database, I decided to use the materialized path, because I know that the nesting will not be very large. I want the path to look like this: 1.1.1.2, 1.1.1.3, 1.1.2.1, etc.
JSON will come in the request body and the application itself will process it and put it into the database.
The database itself will have 4 fields: id, parent_id, name, path.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Ivlev, 2018-11-20
@ivlevdenis_ru

Well go recursively. And your table schema is wrong, instead of parent_id there should be a path in case of a materialized path.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question