6fc1423124
This commit makes Nodes special dicts that return None-like objects for inexistent keys, making it a dynamic attribute store. Also, it removes the D3MapBuilder and moves its logic to the Node and Link classes' newly introduced export() method. Only they need to be changed to populate the final nodes.json with more attributes.
14 lines
314 B
Python
14 lines
314 B
Python
from json import JSONEncoder
|
|
|
|
class CustomJSONEncoder(JSONEncoder):
|
|
"""
|
|
JSON encoder that uses an object's __json__() method to convert it to
|
|
something JSON-compatible.
|
|
"""
|
|
def default(self, obj):
|
|
try:
|
|
return obj.__json__()
|
|
except AttributeError:
|
|
pass
|
|
return super().default(obj)
|