bhargavnova / python-helper-modules

MIT License
7 stars 24 forks source link

Python Script: JSON to CSV #33

Closed bhargavnova closed 9 months ago

bhargavnova commented 9 months ago

Objective

Develop a Python script that converts JSON (JavaScript Object Notation) data to CSV (Comma Separated Values) format. This script will provide a convenient way to transform structured JSON data into a tabular format that can be easily opened and manipulated in spreadsheet software.

Features

Example Usage

import json_to_csv

# Convert JSON to CSV
json_to_csv.convert('input.json', 'output.csv')

# Convert JSON with custom mapping
mapping = {'Name': 'full_name', 'Email': 'contact.email', 'Phone': 'contact.phone'}
json_to_csv.convert('input.json', 'output.csv', field_mapping=mapping)

Difficulty: Intermediate

Tags: Python, JSON, CSV, Data Conversion

Additional Information

Contribution Guidelines

The updated guidelines can be found here.

Note:

akadeepesh commented 9 months ago

let me try this one

ananyapillai72 commented 9 months ago

would like to work on this

bhargavnova commented 9 months ago

Sure!

onkar-kota commented 9 months ago

I'm too working on this issue

bhargavnova commented 9 months ago

Hi @onkar-kota , @ananyapillai72 was already working on this issue, she has also submitted her script, so if you can make another script that can also handle nested dictionaries, if you are interested in that, you can work on that part.

For example, @ananyapillai72 , script can handle the below structure,

    {
        "name": "Test37",
        "status": "done",
        "slug": "test-375960",
        "date": "13-10-2023",
        "author": "unknown",
        "probability": "89%",
        "result": "70%",
        "final_status": "failed"
    },
    {
        "name": "Test38",
        "status": "pending",
        "slug": "test-385960",
        "date": "13-10-2023",
        "author": "unknown",
        "probability": "80%",
        "result": null,
        "final_status": null

    }
]

Now you can working script that can handle below structure,

[
    {
        "name": "Test37",
        "status": "done",
        "slug": "test-375960",
        "date": "13-10-2023",
        "author": "unknown",
        "probability": "89%",
        "result": "70%",
        "final_status": "failed",
        "connected": {
            "run_again": true,
            "next_test": "Test38",
            "next_test_status": "pending"
        }
    },
    {
        "name": "Test38",
        "status": "pending",
        "slug": "test-385960",
        "date": "13-10-2023",
        "author": "unknown",
        "probability": "80%",
        "result": null,
        "final_status": null

    }
]
onkar-kota commented 9 months ago

Ohk got the point, ill try to solve this!

bhargavnova commented 9 months ago

Hi @ananyapillai72, Thank you for your contribution :), you can check on other open issues, or you can also submit one of your own.

Happy Coding!

onkar-kota commented 9 months ago

Hey @bhargavnova should I push to json_to_csv existing folder or should I create a new folder?

bhargavnova commented 9 months ago

Hi @onkar-kota , let's keep it in the same folder, otherwise things will be hard to manage. name your script, json_to_csv_with_nested_dict.py

onkar-kota commented 9 months ago

Hi @bhargavnova I have resolved the issue can you please check my PR #63

bhargavnova commented 9 months ago

Hi @onkar-kota, Thank you for your contribution :), you can check on other open issues, or you can also submit one of your own.

Happy Coding!