💥 JSON objects and arrays can contain infinite levels of nesting & hierarchy, making it difficult to convert complex JSON structures into flattened CSV files. Our online tool shown above solves this problem and automatically flattens out hierarchical JSON objects into multiple CSV files, allowing you to select the CSV that matches your desired level of granularity.
✨ The simplest JSON object to convert into a CSV file is an array of simple objects as shown below. It has a straightforward conversion to a CSV table where each row is an object and each column is an attribute.
[ {"name": "Alice", "salary": 100000}, {"name": "Bob", "salary": 110000}, {"name": "Carol", "salary": 120000} ]
🪺 Things get more complicated when we begin adding levels of nesting to our JSON objects, which can cascade very quickly into complex data structures. If we modify the above example to include a sub-array for each item for "hobbies" we'll see things get a bit trickier, especially when each list of hobbies can have a variable length.
[ {"name": "Alice", "salary": 100000, "hobbies": ["archery"]}, {"name": "Bob", "salary": 110000, "hobbies": ["basketball", "baseball"]}, {"name": "Carol", "salary": 120000, "hobbies": ["croquet", "cats", "cars"]} ]
⚡️ In this case, we parse out the nested JSON into two separate downloadable CSV files instead of trying to cram everything into a single file. The first file labeled "root" contains a row for each person as before as well as the first value listed in the hobbies array. The second file labeled "hobbies" contains a row for each hobby with a reference back to each parent object that's shown when downloading the CSV file:
🗄 The CSV file has a single line for each hobby and repeats the parent object on the right-hand side columns. This is known as denormalized format and is the standard for modern data warehousing and analysis, making it easy to use this data in your research & projects.