1
0
Fork 0
mirror of https://hub.psychoinformatics.de/studyforrest/data-phase2.git synced 2026-07-06 10:04:16 +00:00
data-phase2/code/rawdata_conversion/anon_json
2015-10-01 14:30:13 +02:00

26 lines
531 B
Python
Executable file

#!/usr/bin/python
import sys
import json
import collections
infile = sys.argv[1]
exclude = sys.argv[2:]
j = json.load(open(infile), object_pairs_hook=collections.OrderedDict)
for ex in exclude:
parent = None
obj = j
for e in ex.split('.'):
if not e in obj:
parent = None
obj = j
continue
else:
parent = obj
obj = obj[e]
if not obj is j:
del parent[e]
outfile = open(infile, 'w')
outfile.write('%s\n' % json.dumps(j, indent=4))