json2csvcmd - JSON to CSV Converter¶
Description¶
Use this command line tool to convert JSON files to CSV format
Usage¶
json2csvcmd [-h] [-i] [-o] [-e] [-d] [-k] [-l] [-N] [-X] [-U] [-S] [-c] [-L] [-V]
Optional Arguments¶
Arguments available via the --help
flag:
-h, --help show this help message and exit
-i , --infile JSON file/URL to convert.
-o , --outfile CSV file to be written
-e , --encoding Set the encoding type.
-d, --dump Dump Config settings to file.
-k , --key Key value of target array in file.
-l , --limit Limit total lines written to CSV.
-N, --noheading Skip the headers.
-X, --xlsx Export CSV to Excel(xlsx).
-U, --uselargest Use largest array.
-S, --suppress Suppress line breaks.
-c , --config Config filename to load and use.
-L, --lines Input file is JSON Lines format
-V, --verbose Output helpful messages
-i –infile¶
You must pass the tool either a web url or a file path and you must use
the -i
or --infile
parameter followed by the input as shown in the below. In the first example, we are
loading a .json file that is located in the c:data folder. In the second example, we are loading directly from an example
website URL:
json2csvcmd -i c:\data\example.json
json2csvcmd -i http://www.example.com/example.json`
-o –outfile¶
The -o
or --outfile
parameter sets the file in which to save the converted results. If no parameter is set,
then the output is written to the screen (also known as the console or stdout):
json2csvcmd -i c:\data\example.json -o converted.csv
json2csvcmd -i http://www.example.com/example.json
-e –encoding¶
In order to specify an encoding type for the file, pass the -e
or --encoding
parameter. The most common
encoding types are UTF-8 and UTF-16.
By default, the encoding will be determined for you.
json2csvcmd -i c:\data\example.json -e utf-8
json2csvcmd -i c:\data\example.json --encoding utf-16
json2csvcmd -i c:\data\example.json
-d –dump¶
The -d
or --dump
parameter essentially tells the converter to save the configuration file used in the
conversion. The configuration file can be exported every time a conversion is performed. There is always a default
configuration:
json2csvcmd -i c:\data\example.json -o c:\data\converted.csv -d
json2csvcmd -i http://www.example.com/example.json --dump
-k –key¶
The -k
or --key
flag will generate a keyed JSON file based on the key passed via the flag,
pass a column number or name to identify the column.:
json2csvcmd -i c:\example.json -k id_column
json2csvcmd -i c:\example.json -k 3
-l –limit¶
The -l
or --limit
flag will limit the number of rows written to the CSV file. If no parameter is passed, the
converter will write the entire file. This value must be a number. This parameter will not affect the headers.
json2csvcmd -i c:\example.json -o c:\converted.csv -l 50
json2csvcmd -i c:\example.json -o c:\converted.csv --limit 10
-N –noheading¶
Do not write column headings to the output file. The default value is to include headers.
json2csvcmd -i c:\example.json -o c:\converted.csv -N
-X –xlsx¶
This flag will allow the user to export to Excel (.xlsx) instead of to CSV.
json2csvcmd -i c:\example.json -X
-U –uselargest¶
There are some json data formats that are multilayered, and the first value set may not be the intended set to convert.
The -U
or --uselargest
parameter will tell the converter to focus on whichever parameter set repeats
the most amount of times (and is therefore the largest, and likely target of conversion):
json2csvcmd -i c:\data\example.json -o converted.csv -U
json2csvcmd -i c:\data\example.json -o converted.csv --uselargest
-S –suppress¶
This parameter will suppress line breaks from the output data. More technically, it will remove any carriage returns and line feeds from the data. The default is to allow line breaks:
json2csvcmd -i c:\example.json -o c:\converted.csv -S
json2csvcmd -i c:\example.json -o c:\converted.csv --suppress
-c –config¶
The configuration file used in the conversion is either created at runtime, or passed to the converter before the
conversion begins. The -c
or --config
flag will load a configuration file to used if a path is passed:
json2csvcmd -i c:\example.json -o c:\myoutput.csv -c c:\myconfig.txt
-L –lines¶
The -L
or --lines
flag will tell the converter that the input file is in JSON lines format while
doing the conversion:
json2csvcmd -i c:\example.json -o c:\myoutput.csv -L
json2csvcmd -i c:\example.json -o c:\myoutput.csv --lines
-V –verbose¶
The -V
or --verbose
flag will output useful messages as the program runs:
csv2jsoncmd -i c:\example.csv -V