Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

236
Views
I want to convert CSV to JSON file using python
import csv
import json


# defining the function to convert CSV file to JSON file
def convjson(cleanedhm, js):
    # creating a dictionary
    mydata = {}

    # reading the data from CSV file
    with open(cleanedhm, encoding='utf-8') as csvfile:
        csvRead = csv.DictReader(csvfile)

        # Converting rows into dictionary and adding it to data
        for rows in csvRead:
            mykey = rows['hmid']
            mydata[mykey] = rows

            # dumping the data
    with open('cleanedhm', encoding='utf-8') as jsonfile:
        jsonfile.write(json.dumps(mydata, indent=4))

    # filenames


cleanedhm = r'mydatalist.csv'
js = r'mydatalist.json'

# Calling the convjson function
convjson(cleanedhm, js)
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Pandas is a really great tool, and in this case it does what you need in two very easy lines!

import pandas as pd

csv = pd.read_csv (r'Path where the CSV file is saved\File Name.csv')
csv.to_json (r'Path where the new JSON file will be stored\New File Name.json')
about 4 years ago · Juan Pablo Isaza Report

0

process your file with pandas as a DataFrame and then export with the to_json() method

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!