Arkni / json-to-csv

JSON to CSV converter
Other
54 stars 67 forks source link

JSON To CSV Converter

This is a modified version of json-to-csv project.

This code can be used for generating a flat CSV file from a list of JSON Objects. The JSONFlattener will create list of key-value pairs for the generated JSON. The CSVWriter would write the key value pairs to the specified file.

Usage:

1 - Using a JSON String:

considering the file simple.json in /files directory, contains the following JSON

[
    {
        "studentName": "Foo",
        "Age": "12",
        "subjects": [
            {
                "name": "English",
                "marks": "40"
            },
            {
                "name": "History",
                "marks": "50"
            }
        ]
    },
    {
        "studentName": "Bar",
        "Age": "12",
        "subjects": [
            {
                "name": "English",
                "marks": "40"
            },
            {
                "name": "History",
                "marks": "50"
            },
            {
                "name": "Science",
                "marks": "40"
            }
        ]
    },
    {
        "studentName": "Baz",
        "Age": "12",
        "subjects": []
    }
]

3 - Using a JSON returned from a URL:

for this example, I used the web service echo.jsontest.com to echo a JSON object like the following

{
    "firstName": "Brahim",
    "lastName": "Arkni"
}

N.B:

The sample output files can be seen here.

Licence

See the LICENCE file.