Skip to content

Instantly share code, notes, and snippets.

@jonnyshaw89
Created July 26, 2018 10:52
Show Gist options
  • Save jonnyshaw89/803b9a95c48a94468ca9f10a5b45cba5 to your computer and use it in GitHub Desktop.
Save jonnyshaw89/803b9a95c48a94468ca9f10a5b45cba5 to your computer and use it in GitHub Desktop.
import os
import simplejson as json
directory = "data/en"
for filename in os.listdir(directory):
if filename.endswith(".json"):
print(os.path.join(directory, filename))
with open(os.path.join(directory, filename), encoding='utf8') as json_data:
schema_data = json.load(json_data, use_decimal=True)
metadata = schema_data['metadata']
if isinstance(metadata, dict):
metadata_list = []
for key in metadata.keys():
metadata[key]['validator']
metadata_list.append({"name": key, "validator": metadata[key]['validator']})
schema_data['metadata'] = metadata_list
print("Writing: " + os.path.join(directory, filename))
with open(os.path.join(directory, filename), "w", encoding='utf8') as file:
file.write(json.dumps(schema_data, sort_keys=True))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment