python - Multiple Dictionary JSON file to pandas dataframe -


i have online data of following form:

{"headers": {"ai5": "3356", "debug": null, "random": null, "sd": "7.6"}, "post": {"event": "ggstart", "ts": "1462"}, "params": {}, "bottle": {"timestamp": "2016-05-09 02:00:00.033775", "game_id": "55107008"}}  {"headers": {"ai5": "8fa6", "debug": null, "random": null, "sd": "7.6"}, "post": {"event": "ggstart", "ts": "1475"}, "params": {}, "bottle": {"timestamp": "2016-05-09 02:00:00.004906", "game_id": "55107008"}} 

i expecting have read considering each row json format , keep on adding them final data:

data = [] open('new.json') f:     line in f:         print(line)         data.append(json.loads(line)) 

but receiving error :

jsondecodeerror: expecting value: line 2 column 1 (char 1) 

can 1 please me in understanding important point missing here.

it's because of middle line in file. it's not valid json (a blank line in fact), hence facing error.

fix:

add try/except block.

import json data = [] open('test.txt') f:     line in f:         try:             data.append(json.loads(line.strip()))         except valueerror:             pass  print(data) 

output:

[{ 'post': {     'event': 'ggstart',     'ts': '1462' }, 'bottle': {     'timestamp': '2016-05-09 02:00:00.033775',     'game_id': '55107008' }, 'headers': {     'debug': none,     'sd': '7.6',     'random': none,     'ai5': '3356' }, 'params': {} },  {     'post': {         'event': 'ggstart',         'ts': '1475'     },     'bottle': {         'timestamp': '2016-05-09 02:00:00.004906',         'game_id': '55107008'     },     'headers': {         'debug': none,         'sd': '7.6',         'random': none,         'ai5': '8fa6'     },     'params': {} }] 

Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -