-1

Been trying to implement this code

fg.add_child(folium.GeoJson(data=(open("12.1 world.json", "r", encoding="utf-8-sig")).read()))

Gives me the Error: Extra data: line 1 column 2108737 (char 2108736)

Tried this:

import json
with open('12.1 world.json',encoding="utf-8-sig",errors='ignore') as f:
    data = [json.loads(line,strict=False) for line in f]
Tim
  • 2,510
  • 1
  • 22
  • 26

2 Answers2

1

ya man...actually the file consist of garbage data, I have also gone through that course. the actual size of the json file is different from what you are using.

0

Two things:

  1. This file seems to be a ~2-2.1 megabytes sample from an Udemy course. The offset in the error message refers to a location towards the end of this file, and the message itself complains about extra characters, so the first thing to check would be the very end of the file. Make sure it does not contain any garbage (and especially anything non-whitespace) after the closing } or ]
  2. Do not try to work with JSON data in a line-by-line way, lines (and formatting in general) have no meaning in JSON, they just make it look more pleasant to the human eye. So your own attempt should look like this:

    import json
    with open('12.1 world.json',encoding="utf-8-sig") as f:
      data=json.load(f)
    
tevemadar
  • 12,389
  • 3
  • 21
  • 49