Mar 19 2019
JSON (JavaScript Object Notation) is a relatively new file format for storing and exchanging data and plays an important role in using and processing structured information. So it’s often necessary to convert a CSV file to JSON. There are two non-atomic data types supported by JSON: arrays (ordered lists of values) and objects. Objects are unordered collections of key-values-pairs, where the keys are strings. Each key should be unique within its object.
Tablecruncher for Mac provides an export function to easily achieve this task. A CSV file can be either stored as an array of arrays, where each line is represented as an array. Or it is stored as an array of objects, where each line is an object with the header names as the key and the cells from the line being the values. But let’s look at an example to better understand the difference.
We’re using a simple file to show how easy it is to convert a CSV file to JSON. Please look at the header row, where there are header names “Name”, “Value” and “Category”.
With the command “File > Export JSON …” you’re storing this CSV file as an array of objects because the header rows have been activated. (The JSON file shown below has been reformatted to highlight the structure of the data. Tablecruncher creates files that are not pretty-printed.)
If your CSV file has no header row or the headers should be treated as normal data, you’re deactivating the header row. Now our demo file looks like this:
When we now export that CSV file to JSON, we’ll get a JSON file that’s an array of arrays. (Again I’ve reformatted the JSON to show the structure.)
With Tablecruncher it’s just a single click to convert your CSV files to JSON in one of two possible data structures. If you’ve questions regarding this tutorial or if you have ideas for further tutorials, don’t hesitate to contact me by e-mail: info@tablecruncher.com