0

I have a JSON file (file1.json) that looks this:

{"key":"value","key":"value"}
{"key":"value","key":"value"}

I cant read in this file with pd.read_json('filepath/file1.json') I get error:

ValueError: Expected object or value

I tried opening the file and reading in the with open like so:

with open('~/filepath/file1.json') as f:
    json_data = pd.json_normalize(json.loads(f.read()),encodings='utf-8-sig')

But I get error: json.decoder.JSONDecodeError: Unexpected UTF-8 BOM (decode using utf-8-sig): line 1 column 1 (char 0)

However, when I read remove all rows except the top 2 from the file and add a comma like so:

{"key":"value","key":"value"},
{"key":"value","key":"value"} 

I can read in the file as is with pd.read_json().

How can I read in the file with non comma separated file dict objects per line?

Thanks in advance.

RustyShackleford
  • 3,462
  • 9
  • 40
  • 81

1 Answers1

1

I believe you must use json.JSONDecoder()

Check this:

complex json file to csv in python

and this:

how to analyze json objects that are NOT separated by comma (preferably in Python)

You have to read the json, put the dicts in list and then use pd.json_normalize()

diml
  • 136
  • 4