Skip to content

Instantly share code, notes, and snippets.

@maltzsama
Created May 15, 2018 18:41
Show Gist options
  • Save maltzsama/ff57553bceb5aa48ef572d5cb90ab7d3 to your computer and use it in GitHub Desktop.
Save maltzsama/ff57553bceb5aa48ef572d5cb90ab7d3 to your computer and use it in GitHub Desktop.
parser try
#!/usr/bin/env python
import json
def json_decode(info = None, table = None, visitorId = None):
# print table
table_dict = {}
keys = info.keys()
for k in keys:
if type(info[k]) == dict:
json_decode(info[k], k, visitorId)
elif type(info[k]) == list:
for el in info[k]:
json_decode(el, k, visitorId)
else:
table_dict[k] = info[k]
with open('table/' + table + '.txt', "a+") as f:
keys = table_dict.keys()
for k in keys:
f.write(k + ':' + str( table_dict[k]) + ' \n')
with open('santander-PJ.json') as f:
data = json.load(f)
x = {}
for n in data:
if 'fullVisitorId' in n:
visitorId = n['fullVisitorId']
x = json_decode(n, table = 'main', visitorId = visitorId)
print x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment