-
Notifications
You must be signed in to change notification settings - Fork 0
/
nested_ex2.py
40 lines (36 loc) · 1.13 KB
/
nested_ex2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from serial_j import SerialJ
class SnackBucket(SerialJ):
schema = [
{'name': 'apple'},
{'name': 'orange'},
{'name': 'pineapple'},
{'name': 'snack', 'is_compound': True,
'compound_schema': [
{'name': 'cheese', 'optional': True},
{'name': 'chocolate'},
{'name': 'chips', 'nullable': True},
],
},
]
test3 = dict(
apple="good apple",
orange="very good orange",
pineapple="nice pineapple",
snack=[
dict(
cheese="Feta",
chocolate="Ferrero Rocher",
chips=[]
),
dict(
chocolate="Swiss milk chocolate",
chips=["Cheetos", "Lays Classic Potato Chips", "Cool Ranch Doritos"]
),
]
)
mysnacks = SnackBucket(test3)
print(mysnacks)
# >>> {"apple": "good apple", "orange": "very good orange", "pineapple": "nice pineapple",
# >>> "snack": [{"cheese": "Feta", "chocolate": "Ferrero Rocher", "chips": []},
# >>> {"chocolate": "Swiss milk chocolate", "chips":
# >>> ["Cheetos", "Lays Classic Potato Chips", "Cool Ranch Doritos"]}]}