Commit be3d879e authored by C. Albrecht's avatar C. Albrecht
Browse files

NEW: added script thing_to_ditto_thing.py

parent 39e32122
import json
def add_feature(features, feature_id, feature_name):
short_id = feature_id[14:]
properties = {feature_name : ""}
features[short_id] = {"properties" : properties}
def transform(obj, features):
for key in obj:
value = obj[key]
if isinstance(value, dict):
transform(value, features)
elif isinstance(value, list):
for ele in value:
if isinstance(ele, dict):
transform(ele, features)
elif isinstance(value, str):
if value.startswith("ditto-feature:"):
add_feature(features, value, key)
def main():
filename = ""
with open(filename, "r") as in_file:
thing = json.load(in_file)
features = thing.get("features", None)
if not features:
features = {}
thing["features"] = features
transform(thing, features)
print(json.dumps(thing, indent=2))
main()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment