Bonobo in action ...

How to convert a file from CSV to JSON

Bonobo can be used to convert files from and to various data sources and file formats. You can use it from command line to convert a CSV file into JSON, or create a transformation if you need more flexibility or different transformation steps.

You do not need to know Python to use bonobo convert, only how to use a shell and have a shell where you can install python packages.

Installation

If you never used bonobo, you first need to install it. To know if bonobo is installed, you can run bonobo version (and it should be at least 0.5)

$ pip install bonobo

(read about more installation options in the documentation)

Convert CSV to JSON from command line

Simple as hell, just give the input and output file names to bonobo convert and you're good to go.

$ bonobo convert input.csv output.json

If bonobo can't detect your source file format (or your output does not end by .json), you can provide input format, output format, or both as optional arguments in the command line.

$ bonobo convert --reader csv input_file --writer json output_file

Or the shorthand version...

$ bonobo convert -r csv input_file -w json output_file

Need more? Write your first transformation!

Writing a transformation is easy. Here is an equivalent transformation to the command line example above.

Create a convert_csv_to_json.py file, and paste the following code:

import bonobo

graph = bonobo.Graph(
    bonobo.CsvReader('input.csv'),
    bonobo.JsonWriter('output.json'),
)

if __name__ == '__main__':
    bonobo.run(graph)

Now, you can use bonobo run to execute it.

$ bonobo run convert_csv_to_json.py

If you're ready to go further and learn what you can do between the read and write phases, go ahead and read the 10 minutes to bonobo tutorial.

Happy format conversions!

Did I say we need feedback? Slack discussions and issues are more than welcome!