csvjson1
Csvjson documentation
Overview
Converts a CSV file into JSON or GeoJSON (depending on flags):
usage: csvjson [-h] [-d DELIMITER] [-t] [-q QUOTECHAR] [-u {0,1,2,3}] [-b][-p ESCAPECHAR] [-z FIELD_SIZE_LIMIT] [-e ENCODING] [-L LOCALE][-S] [--blanks] [--null-value NULL_VALUES [NULL_VALUES ...]][--date-format DATE_FORMAT] [--datetime-format DATETIME_FORMAT][-H] [-K SKIP_LINES] [-v] [-l] [--zero] [-V] [-i INDENT][-k KEY] [--lat LAT] [--lon LON] [--type TYPE][--geometry GEOMETRY] [--crs CRS] [--no-bbox] [--stream][-y SNIFF_LIMIT] [-I][FILE]Convert a CSV file into JSON (or GeoJSON).positional arguments:FILE The CSV file to operate on. If omitted, will acceptinput as piped data via STDIN.optional arguments:-h, --help show this help message and exit-i INDENT, --indent INDENTIndent the output JSON this many spaces. Disabled bydefault.-k KEY, --key KEY Output JSON as an object keyed by a given column, KEY,rather than as an array. All column values must beunique. If --lat and --lon are specified, this columnis used as the GeoJSON Feature ID.--lat LAT A column index or name containing a latitude. Outputwill be GeoJSON instead of JSON. Requires --lon.--lon LON A column index or name containing a longitude. Outputwill be GeoJSON instead of JSON. Requires --lat.--type TYPE A column index or name containing a GeoJSON type.Output will be GeoJSON instead of JSON. Requires --latand --lon.--geometry GEOMETRY A column index or name containing a GeoJSON geometry.Output will be GeoJSON instead of JSON. Requires --latand --lon.--crs CRS A coordinate reference system string to be includedwith GeoJSON output. Requires --lat and --lon.--no-bbox Disable the calculation of a bounding box.--stream Output JSON as a stream of newline-separated objects,rather than an as an array.-y SNIFF_LIMIT, --snifflimit SNIFF_LIMITLimit CSV dialect sniffing to the specified number ofbytes. Specify "0" to disable sniffing entirely, or"-1" to sniff the entire file.-I, --no-inference Disable type inference (and --locale, --date-format,--datetime-format, --no-leading-zeroes) when parsingthe input.
See also: Arguments common to all tools.
Examples
Convert veteran's education dataset to JSON keyed by state abbreviation:
$ csvjson -k "State Abbreviate" -i 4 examples/realdata/FY09_EDU_Recipients_by_State.csv{"AL": {"State Name": "ALABAMA","State Abbreviate": "AL","Code": 1.0,"Montgomery GI Bill-Active Duty": 6718.0,"Montgomery GI Bill- Selective Reserve": 1728.0,"Dependents' Educational Assistance": 2703.0,"Reserve Educational Assistance Program": 1269.0,"Post-Vietnam Era Veteran's Educational Assistance Program": 8.0,"TOTAL": 12426.0,"j": null},"...": {"...": "..."}}
Convert locations of public art into GeoJSON:
$ csvjson --lat latitude --lon longitude --k slug --crs EPSG:4269 -i 4 examples/test_geo.csv{"type": "FeatureCollection","bbox": [-95.334619,32.299076986939205,-95.250699,32.351434],"crs": {"type": "name","properties": {"name": "EPSG:4269"}},"features": [{"type": "Feature","id": "dcl","geometry": {"type": "Point","coordinates": [-95.30181,32.35066]},"properties": {"title": "Downtown Coffee Lounge","artist": null,"description": "In addition to being the only coffee shop in downtown Tyler, DCL also features regular exhibitions of work by local artists.","install_date": null,"address": "200 West Erwin Street","type": "Gallery","photo_url": null,"photo_credit": null,"last_seen_date": "2012-03-30"}},{"...": "..."}],"crs": {"type": "name","properties": {"name": "EPSG:4269"}}}
Releases
4 releases since Debian 11 (Bullseye); the text changed 3 times.
--blanks until Debian 12 (Bookworm);
--crs until Debian 12 (Bookworm);
--date-format until Debian 12 (Bookworm);
--datetime-format until Debian 12 (Bookworm);
--delimiter until Debian 12 (Bookworm);
--encoding until Debian 12 (Bookworm);
--escapechar until Debian 12 (Bookworm);
--geometry until Debian 12 (Bookworm);
--help until Debian 12 (Bookworm);
--indent until Debian 12 (Bookworm);
--key until Debian 12 (Bookworm);
--lat until Debian 12 (Bookworm);
--linenumbers until Debian 12 (Bookworm);
--locale until Debian 12 (Bookworm);
--lon until Debian 12 (Bookworm);
--maxfieldsize until Debian 12 (Bookworm);
--no-bbox until Debian 12 (Bookworm);
--no-doublequote until Debian 12 (Bookworm);
--no-header-row until Debian 12 (Bookworm);
--no-inference until Debian 12 (Bookworm);
--quotechar until Debian 12 (Bookworm);
--quoting until Debian 12 (Bookworm);
--skip-lines until Debian 12 (Bookworm);
--skipinitialspace until Debian 12 (Bookworm);
--snifflimit until Debian 12 (Bookworm);
--stream until Debian 12 (Bookworm);
--tabs until Debian 12 (Bookworm);
--type until Debian 12 (Bookworm);
--verbose until Debian 12 (Bookworm);
--version until Debian 12 (Bookworm);
--zero until Debian 12 (Bookworm);
-H until Debian 12 (Bookworm);
-I until Debian 12 (Bookworm);
-K until Debian 12 (Bookworm);
-L until Debian 12 (Bookworm);
-S until Debian 12 (Bookworm);
-V until Debian 12 (Bookworm);
-b until Debian 12 (Bookworm);
-d until Debian 12 (Bookworm);
-e until Debian 12 (Bookworm);
-h until Debian 12 (Bookworm);
-i until Debian 12 (Bookworm);
-k until Debian 12 (Bookworm);
-l until Debian 12 (Bookworm);
-p until Debian 12 (Bookworm);
-q until Debian 12 (Bookworm);
-t until Debian 12 (Bookworm);
-u until Debian 12 (Bookworm);
-v until Debian 12 (Bookworm);
-y until Debian 12 (Bookworm);
-z until Debian 12 (Bookworm).