This is my JSON data
[
{
"id":1,
"name":"abc",
"phone": "12345",
"Charecteristics": [
{
"id":1,
"name":"Good Looking",
"rating": "Average",
}
{
"id":2,
"name":"Smart",
"rating": "Excellent",
}
]
},
{ ... },
{ ... }
]
I have two Classes in Python
class Character(object):
id = 0
name = ""
rating = ""
class Person(object):
id = 0
name = ""
phone = ""
Characteristics = []
I need to parse the JSON data and instantiate appropriate Classes. The Classes are self-explanatory: i.e. Person has an array of Character classes.
How do I instantiate these and store data appropriately?
Also, how will I access particular Person data? i.e. Person's details and characteristics
If you are writing in python 3.6+, the easiest is probably to use marshmallow-dataclass :
Take a look at colander; it makes turning a JSON data structure into Python objects dead easy.
You define a schema:
then pass in your JSON data structure using the following: