Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ValueError : embedded null character while Importing a JSON file using python [duplicate]

Tags:

python

json

I'm trying to import a JSON file in python but I keep running into an error

with open('e:\0_1export.json', 'r') as f:
data = f.read().strip();

Error message:

ValueError                                Traceback (most recent call last)
<ipython-input-40-abd9cb3a729a> in <module>()
----> 1 with open('e:\0_1export.json', 'r') as f:
  2     data = f.read().strip();

ValueError: embedded null character

Here is the pastebin of the contents of the file i am trying to import .

https://pastebin.com/mCZiPktJ

Any help is appreciated!

like image 343
Abhinav H Avatar asked Jan 21 '26 14:01

Abhinav H


1 Answers

'e:\0_1export.json' must be written as 'e:\\0_1export.json' or r'e:\0_1export.json'. Otherwise, Python treats '\0' as a NULL character (the character with the code 0).

like image 108
DYZ Avatar answered Jan 23 '26 03:01

DYZ