Skip to content

The code to flatten json objects and convert an array of json objects to CSV with column names generated dynamically.

License

Notifications You must be signed in to change notification settings

DaniBunny/FlattenJSON

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

####JSON To CSV Converter

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.

For example, consider the JSON format:

[
    {
        "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": []
    }
]

would generate a CSV as below:

Age studentName subjects1marks subjects1name subjects2marks subjects2name subjects3marks subjects3name
12 Foo 40 English 50 History
12 Bar 40 English 50 History 40 Science
12 Baz

The column names would dynamically be generated based on the keys in the JSON object.

The sample output file can be seen here.

About

The code to flatten json objects and convert an array of json objects to CSV with column names generated dynamically.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%