profile picture

instantiator.dev

tech, volunteers, public safety, collective intelligence, articles, tools, code and ideas

© Lewis Westbury 2024

Hammering JSON into CSV

tool hack

json-to-smart-csv is a tool to help build CSV records from arbitrary JSON…

Hammering JSON into CSV

I’ve built a simple tool to help hammer arbitrary JSON into CSV records.

You’re welcome to pilfer it, use it, and adapt it to your needs. If you make any modifications, do please upstream your improvements.

Download the latest binaries from:

Getting started

Take a look in the sample-data directory to get a feel for the tool.

  • sample-list.json is a JSON file containing several rich objects - representing a number of fruit/vegetables found in the kitchen.
  • sample-rules.csv defines a number of columns to create in output CSV, and how to source them from the JSON.
  • sample-out.csv is the output generated by the tool.

sample output

(Mac OS) You can regenerate the test output by running the test-sample-osx-x64.sh script.

As you can see from the script, it provides these arguments to JsonToSmartCsv:

  • -c sample-data/sample-rules.csv - indicating the CSV file to find column definitions in
  • -s sample-data/sample-list.json - indicating the source data JSON file
  • -t sample-data/sample-out.csv - indicating the target file to put the results

By default it runs in Create mode - but you can switch it to append to the target file by adding the -m Append option.

Future work

It’s about as feature-complete as I need it to be. If you want to improve on it, or publish to a package manager of your choice, you’re very welcome to do so - and do please upstream your changes.