-
Notifications
You must be signed in to change notification settings - Fork 0
/
example-1.py
50 lines (44 loc) · 1.11 KB
/
example-1.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
41
42
43
44
45
46
47
48
49
50
# Add parent directory to path to be able to import json_transformer
import sys
sys.path.append('../')
# The above part can be omitted if json_transformer is installed as a package
from json_dict_transformer import translateDictToDict
class MyFuncCollection:
def upperLetters(input: str) -> str:
return input.upper()
input_dict = {
"name": "John",
"surname": "Doe",
"age": 30,
"address": {
"street": "Main Street",
"number": 123,
"city": "New York",
"country": "USA"
},
"hobbies": [
"football",
"basketball",
"tennis"
]
}
schema_dict = {
"full name": ["json::name", "txt:: ", "json::surname"],
"age": ["json::age"],
"address": [
"json::address.street",
"txt::,",
"json::address.number",
"txt::,",
"json::address.city",
"txt::,",
"json::address.country"
],
"hobbies": [
"txt::My hobbies are: ",
"func::upperLetters",
"json::hobbies",
]
}
output_dict = translateDictToDict(input_dict, schema_dict, MyFuncCollection)
print(output_dict)