-1

I have a json file and I am trying to load its contents line by line using json.loads command but I am getting below error-

"simplejson.errors.JSONDecodeError: Invalid control character '\x00' at: line 1 column 536 (char 535)"

Code snippet-

import simplejson as json
   with open(file_path) as file:
      for line in file:
         line_contents = json.loads(line)#.replace('\x00',' ')

Note: I also tried replacing '\x00' with ' ' but it didn't help and threw another error-

"simplejson.errors.JSONDecodeError: Unterminated string starting at: line 1 column 163 (char 162)"

Any help would be appreciated!

1 Answers1

0

This happens a lot of times, depending on what environment your input file came from. Try this:

import simplejson as json
   with open(file_path) as file:
      for line in file:
         line_contents = json.loads(line, strict=False)
Prateek Dewan
  • 1,587
  • 3
  • 16
  • 29
  • I tried this code using 'strict=False' but it throws error- "simplejson.errors.JSONDecodeError: Unterminated string starting at: line 1 column 163 (char 162)" – Akshat Agrawal Feb 20 '20 at 03:51
  • Are you sure the JSON you're parsing is valid? Try using https://jsonlint.com to validate your JSON... – Prateek Dewan Feb 20 '20 at 03:57