-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
55 lines (40 loc) · 1.52 KB
/
test.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
51
52
53
54
from JSON4JSON import JSON4JSON
import json
import objgraph
def reverse(data, ruleset, j4j, parentUID):
return data[::-1]
config = JSON4JSON()
config.add_transform(reverse, name='reverse')
path = "./tests/3/"
config.load(f"{path}config.json", f"{path}rules.json")
print("\n\n")
#print("variables:", config.vars)
def removeUnderscored(d, keep=[]):
doItAgain = False
for key in d:
if key.startswith("_") and key not in keep:
#reMOVE
del d[key]
doItAgain = True
break
if type(d[key]) == dict:
removeUnderscored(d[key], keep=keep)
if doItAgain:
removeUnderscored(d, keep=keep)
def getObjectPath(myKey, o, level=0):
txt = level * "-" + myKey
for key in o:
if key.startswith("_"):
continue
if type(o[key]) == dict:
txt += "\n" + getObjectPath(key, o[key], level = level + 3)
return txt
print(getObjectPath("root", config.data, level=0))
#print("parent", config.getParent(config.data['someObject2']['nestedObject']['anotherObject'], level = 0)['_uid'], config.data['someObject2']['nestedObject']['anotherObject']['_uid'])
removeUnderscored(config.data, keep=["_uid", "_parent", "_variables"])
objgraph.show_refs(config.data, max_depth=8)
#dumps the converted dictionary to output.json.
#this is good for getting a reference for what your config object will look like when you use advancedJSON
json.dump(config.data, open(f"{path}output.json", "w+"), indent=4)
json.dump(config.rules, open(f"{path}outputtedRules.json", "w+"), indent=4)
json.dump(config.objects, open(f"{path}uids_objects.json", "w+"), indent=4)