1

I have the following JSON file thats generated from a call to a datastream. Using the code below, I'm unable to open the file and instead get the following error:

raise JSONDecodeError("Extra data", s, end)
json.decoder.JSONDecodeError: Extra data: line 2 column 1

I used Jsonlint and get the following error:

Expecting 'EOF', '}', ',', ']', got '{'

I have tried opening the file through pandas and it also doesn't work. Any help will be appreciated, not sure how to debug this on my end.

from pprint import pprint

datajson = 'errortest.json'

with open(datajson) as f:
    data = json.load(f)

pprint(data)

Output:

{"target": {"icao_address": "A1AE05", "timestamp": "2019-10-27T22:25:55Z", "altitude_baro": 26000, "heading": 330.0, "speed": 389.9, "latitude": 34.636047, "longitude": -118.822127, "callsign": "SWA5282", "collection_type": "terrestrial", "ingestion_time": "2019-10-27T22:25:59Z", "tail_number": "N207WN", "icao_actype": "B737", "flight_number": "WN5282", "origin_airport_icao": "KLGB", "destination_airport_icao": "KOAK", "scheduled_departure_time_utc": "2019-10-27T22:05:00Z", "scheduled_departure_time_local": "2019-10-27T15:05:00", "scheduled_arrival_time_utc": "2019-10-27T23:20:00Z", "scheduled_arrival_time_local": "2019-10-27T16:20:00"}}
{"target": {"icao_address": "AB79DE", "timestamp": "2019-10-27T22:25:55Z", "altitude_baro": 30025, "heading": 260.0, "speed": 410.0, "latitude": 35.850716, "longitude": -101.077667, "callsign": "AAL2102", "collection_type": "terrestrial", "ingestion_time": "2019-10-27T22:25:59Z", "tail_number": "N839AW", "icao_actype": "A319", "flight_number": "AA2102", "origin_airport_icao": "KCMH", "destination_airport_icao": "KLAX", "scheduled_departure_time_utc": "2019-10-27T20:03:00Z", "scheduled_departure_time_local": "2019-10-27T16:03:00", "scheduled_arrival_time_utc": "2019-10-28T01:00:00Z", "scheduled_arrival_time_local": "2019-10-27T18:00:00", "estimated_arrival_time_utc": "2019-10-28T00:56:00Z", "estimated_arrival_time_local": "2019-10-27T17:56:00"}}
martineau
  • 119,623
  • 25
  • 170
  • 301
Zayn_SE
  • 153
  • 1
  • 1
  • 13

1 Answers1

1

That's not JSON. That's a bunch of separate JSON strings written to the same file on separate lines. It's commonly referred to as "JSON Lines", and the usual, less-confusing extension for such a file would be .jsonl, not .json.

Read individual lines and pass them to json.loads.

user2357112
  • 260,549
  • 28
  • 431
  • 505
  • Gave upvote to user2357112, you saved me hours of work for pointing me the right direction. For now, I'm going to pass the error on the final line as an except and work with the collected data. – Zayn_SE Oct 28 '19 at 00:29