Blindly convert from CSV to JSON while using the CSV headers as keys for the JSON objects. Also works with TSV files or any file that can be delimited.
shards build c2j --release
move somewhere in your $PATH
Add it to shard.yml
dependencies:
csv-to-json:
github: silasb/csv-to-json.cr
version: 0.3.3
Build the documentation by cloning this repo and running crystal doc
. HTML documentation will be placed in doc/
.
Usage:
./c2j [flags...] <file> [arg...]
Flags:
--delimiter, -d
--empty-value-replace-char, -e
--help (default: false) # Displays help for the current command.
--quote-char, -q
--tail, -t
--version (default: false)
Convert CSV to JSON
c2j some.csv
Convert TSV to JSON
c2j -d '\t' -q '|' some.txt
Parsing empty CSV cells with something other than null
by using --empty-value-replace-char
c2j --empty_value_replace_char '' some.txt
{ "hello": "" }
instead of:
{ "hello": null }
Used with jq
to quickly filter and display data
c2j some.csv | jq '.[] | select(.["Last Name"] == "Rutledge")'
Find records, but redefine all matching objects
c2j some.csv | jq '.[] | select(.["Last Name"] == "Rutledge") | { last_name: ."Last Name", first_name: ."First Name" }'
Used to convert CSV to a format that esbulk
can use
c2j -d '\t' -q '|' LATEST.txt | jq -c '.[] | .' | esbulk -index some-index
TODO: Write development instructions here
- Fork it ( https://github.com/silasb/csv-to-json/fork )
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create a new Pull Request
- [silasb] silasb - creator, maintainer