0

I'm tring to do:

import pandas as pd
df = pd.read_json('2016-06-20-2359Z.json') 

And I'm taking this error:

ValueError: Trailing data 

Here is a short version of the json file:

{"src":1,"feeds":[{"id":1,"name":"ADSBexchange.com","polarPlot":false}],"srcFeed":1,"showSil":true,"showFlg":true,"showPic":true,"flgH":20,"flgW":85,"acList":[{"Id":11281748,"Rcvr":1,"HasSig":false,"Icao":"AC2554","Bad":false,"Reg":"N882AS","FSeen":"\/Date(1466467166951)\/","TSecs":3,"CMsgs":1,"AltT":0,"Tisb":false,"TrkH":false,"Type":"CRJ2","Mdl":"2001 BOMBARDIER INC CL-600-2B19","Man":"Bombardier","CNum":"7503","Op":"EXPRESSJET AIRLINES INC     - ATLANTA, GA","OpIcao":"ASQ","Sqk":"","VsiT":0,"WTC":2,"Species":1,"Engines":"2","EngType":3,"EngMount":1,"Mil":false,"Cou":"United States","HasPic":false,"Interested":false,"FlightsCount":0,"Gnd":false,"SpdTyp":0,"CallSus":false,"TT":"a","Trt":1,"Year":"2001"},{"Id":11402205,"Rcvr":1,"HasSig":true,"Sig":110,"Icao":"ADFBDD","Bad":false,"FSeen":"\/Date(1466391940977)\/","TSecs":75229,"CMsgs":35445,"Alt":8025,"GAlt":8025,"AltT":0,"Call":"TEST1234","Tisb":false,"TrkH":false,"Sqk":"0262","Help":false,"VsiT":0,"WTC":0,"Species":0,"EngType":0,"EngMount":0,"Mil":true,"Cou":"United States","HasPic":false,"Interested":false,"FlightsCount":0,"Gnd":true,"SpdTyp":0,"CallSus":false,"TT":"a","Trt":1}],"totalAc":4231,"lastDv":"636019887431643594","shtTrlSec":61,"stm":1466467170029}

Is there anybody who can see why?

Alperen
  • 3,772
  • 3
  • 27
  • 49
user8149657
  • 513
  • 1
  • 6
  • 11
  • Is this a line of the json file? Does the json file contain more than one lines like this line? – Alperen Sep 23 '17 at 13:27
  • Yes, it is a line of the json file. it just inside the line has many of {"Id":11281748,"Rcvr":1,"HasSig":false,"Icao":"AC2554","Bad":false,"Reg":"N882AS","FSeen":"/Date(1466467166951)/","TSecs":3,"CMsgs":1,"AltT":0,"Tisb":false,"TrkH":false,"Type":"CRJ2","Mdl":"2001 BOMBARDIER INC CL-600-2B19","Man":"Bombardier","CNum":"7503","Op":"ATLANTA, GA","OpIcao":"ASQ","Sqk":"","VsiT":0,"WTC":2,"Species":1,"Engines":"2","EngType":3,"EngMount":1,"Mil":false,"Cou":"United States","HasPic":false,"Interested":false,"FlightsCount":0,"Gnd":false,"SpdTyp":0,"CallSus":false,"TT":"a","Trt":1,"Year":"2001"}, – user8149657 Sep 23 '17 at 13:30
  • if I delete {"src":1,"feeds":[{"id":1,"name":"ADSBexchange.com","polarPlot":false}],"srcFeed":1,"showSil":true,"showFlg":true,"showPic":true,"flgH":20,"flgW":85,"acList": at the beginning and the end ,"totalAc":4231,"lastDv":"636019887431643594","shtTrlSec":61,"stm":1466467170029} it will works find. However I would like to get a method to read the original file, because there are so many such files that I can't do it each by hand. – user8149657 Sep 23 '17 at 13:38
  • Did you try "lines" parameter in my answer below? – Alperen Sep 23 '17 at 13:40

1 Answers1

0

Use "lines" parameter if your pandas module is up-to-date:

df = pd.read_json('2016-06-20-2359Z.json', lines=True)
Alperen
  • 3,772
  • 3
  • 27
  • 49
  • OMG, that works. I thought I did try this once but it wasn't working. Now it works. Thank you Alperen – user8149657 Sep 23 '17 at 13:51
  • Sorry Alperen, I have another question for you on the same subject. Now all my data are in the df.acList column. How can I take df.acList 'Id', 'Rcvr'...... into new columns? 0 [{'Id': 11281748, 'Rcvr': 1, 'HasSig': False, ... Name: acList, dtype: object – user8149657 Sep 23 '17 at 14:39