-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjsonHandler.py
More file actions
37 lines (29 loc) · 969 Bytes
/
jsonHandler.py
File metadata and controls
37 lines (29 loc) · 969 Bytes
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
#!/usr/bin/env python
import sys
import json
def flattenJson(init, lkey=''):
ret = {}
for rkey, val in init.items():
key = lkey+rkey
if isinstance(val,dict):
# print '%s is a dict' % (rkey)
ret.update(flattenJson(val,key+'_'))
# elif isinstance(val,list):
# l = []
# for v in val:
# if isinstance(v,dict):
# l.append(flattenJson(v,key+'_'))
# # ret.update(l)
# else:
# l.append(v)
# ret[key] = l
else:
# print '%s is a value' % (rkey)
ret[key] = val
return ret
# line = open('/home/mark_jacobson/local_pipeline/KH-Analytics/test/py/source_catalog/source_catalog_20170501.json','r')
# json_data = line.read().split("\t")
# for i in json_data:
# jsonRecord = json.loads(i)
# for i in jsonRecord[:1]:
# print json.dumps(flattenJson(i))