0

this is my code covert json into csv.

import csv
import json
with open('Documents/SampleCSVStory.csv', 'r') as f:
    reader = csv.reader(f, delimiter=';')
    data_list = list()
    for row in reader:
        data_list.append(row)
data = [dict(zip(data_list[0],row)) for row in data_list]
data.pop(0)
s = json.dumps(data)
print (s)

but the output coming like this

[{"Id,Name,Description": "1,User 1,Python Developer"}

my expectation is

[{"Id:"1",Name:"User 1",Description:"Python Developer"}

can anyone helping me in this please.?

1 Answer 1

1
import csv
import json

with open('Documents/SampleCSVStory.csv', 'r') as f:
    reader = csv.DictReader(f, delimiter=';')
json.dumps([row for row in reader])
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.