0

I need to parse a json with top level array but I am getting following error. I can remove the top level [] but I guess there should be an easy way I am missing.

File contents:

[{"name": "Bob", "languages": ["English", "Fench"]}]

Error:

AttributeError: 'list' object has no attribute 'json'

Code:

data = json.load(json_file)
links = data.json()
deadshot
  • 8,881
  • 4
  • 20
  • 39
user3741611
  • 327
  • 2
  • 16

1 Answers1

1

As a workaround, added dummy top level element and parsed:

data = '{"persons":'+file.read(json_file)+'}'
personsdict = json.loads(data)
print(packagedict['persons'][0]['languages'])
user3741611
  • 327
  • 2
  • 16