chqdrian
chqdrian

Reputation: 345

convert CSV to JSON using Python

I need to convert a CSV file to JSON file using Python. I used this,

variable = csv.DictReader(file.csv)

It throws this ERROR

csv.Error: line contains NULL byte

I checked the CSV file in Excel, it shows no NULL chars, but when I printed the data in CSV file using Python. There are some data like SOHNULNULHG (here last 2 letters, HG is the data displaying in the Excel). I need to remove these ASCII chars in the CSV file, while converting to JSON. (i.e. I need only HG from the above string)

Upvotes: 1

Views: 894

Answers (1)

brehma
brehma

Reputation: 206

I just ran into the same issue. I converted my csv file to csv UTF-8 and ran it again without any errors. That seemed to fix the ASCII char issue. Hope that helps.

To convert the csv type, I just opened my file up in Excel, did save as, then selected CSV UTF-8(Comma delimited)(*.csv) in the Save as type.

Hope that helps.

Upvotes: 1

Related Questions