Debian Codegraph @

docs/scripts/csvjson.rst

raw
1 =======
2 csvjson
3 =======
4
5 Description
6 ===========
7
8 Converts a CSV file into JSON or GeoJSON (depending on flags):
9
10 .. code-block:: none
11
12 usage: csvjson [-h] [-d DELIMITER] [-t] [-q QUOTECHAR] [-u {0,1,2,3}] [-b]
13 [-p ESCAPECHAR] [-z FIELD_SIZE_LIMIT] [-e ENCODING] [-L LOCALE]
14 [-S] [--blanks] [--null-value NULL_VALUES [NULL_VALUES ...]]
15 [--date-format DATE_FORMAT] [--datetime-format DATETIME_FORMAT]
16 [-H] [-K SKIP_LINES] [-v] [-l] [--zero] [-V] [-i INDENT]
17 [-k KEY] [--lat LAT] [--lon LON] [--type TYPE]
18 [--geometry GEOMETRY] [--crs CRS] [--no-bbox] [--stream]
19 [-y SNIFF_LIMIT] [-I]
20 [FILE]
21
22 Convert a CSV file into JSON (or GeoJSON).
23
24 positional arguments:
25 FILE The CSV file to operate on. If omitted, will accept
26 input as piped data via STDIN.
27
28 optional arguments:
29 -h, --help show this help message and exit
30 -i INDENT, --indent INDENT
31 Indent the output JSON this many spaces. Disabled by
32 default.
33 -k KEY, --key KEY Output JSON as an object keyed by a given column, KEY,
34 rather than as an array. All column values must be
35 unique. If --lat and --lon are specified, this column
36 is used as the GeoJSON Feature ID.
37 --lat LAT A column index or name containing a latitude. Output
38 will be GeoJSON instead of JSON. Requires --lon.
39 --lon LON A column index or name containing a longitude. Output
40 will be GeoJSON instead of JSON. Requires --lat.
41 --type TYPE A column index or name containing a GeoJSON type.
42 Output will be GeoJSON instead of JSON. Requires --lat
43 and --lon.
44 --geometry GEOMETRY A column index or name containing a GeoJSON geometry.
45 Output will be GeoJSON instead of JSON. Requires --lat
46 and --lon.
47 --crs CRS A coordinate reference system string to be included
48 with GeoJSON output. Requires --lat and --lon.
49 --no-bbox Disable the calculation of a bounding box.
50 --stream Output JSON as a stream of newline-separated objects,
51 rather than an as an array.
52 -y SNIFF_LIMIT, --snifflimit SNIFF_LIMIT
53 Limit CSV dialect sniffing to the specified number of
54 bytes. Specify "0" to disable sniffing entirely, or
55 "-1" to sniff the entire file.
56 -I, --no-inference Disable type inference (and --locale, --date-format,
57 --datetime-format, --no-leading-zeroes) when parsing
58 the input.
59
60 See also: :doc:`../common_arguments`.
61
62 Examples
63 ========
64
65 Convert veteran's education dataset to JSON keyed by state abbreviation:
66
67 .. code-block:: console
68
69 $ csvjson -k "State Abbreviate" -i 4 examples/realdata/FY09_EDU_Recipients_by_State.csv
70 {
71 "AL": {
72 "State Name": "ALABAMA",
73 "State Abbreviate": "AL",
74 "Code": 1.0,
75 "Montgomery GI Bill-Active Duty": 6718.0,
76 "Montgomery GI Bill- Selective Reserve": 1728.0,
77 "Dependents' Educational Assistance": 2703.0,
78 "Reserve Educational Assistance Program": 1269.0,
79 "Post-Vietnam Era Veteran's Educational Assistance Program": 8.0,
80 "TOTAL": 12426.0,
81 "j": null
82 },
83 "...": {
84 "...": "..."
85 }
86 }
87
88 Convert locations of public art into GeoJSON:
89
90 .. code-block:: console
91
92 $ csvjson --lat latitude --lon longitude --k slug --crs EPSG:4269 -i 4 examples/test_geo.csv
93 {
94 "type": "FeatureCollection",
95 "bbox": [
96 -95.334619,
97 32.299076986939205,
98 -95.250699,
99 32.351434
100 ],
101 "crs": {
102 "type": "name",
103 "properties": {
104 "name": "EPSG:4269"
105 }
106 },
107 "features": [
108 {
109 "type": "Feature",
110 "id": "dcl",
111 "geometry": {
112 "type": "Point",
113 "coordinates": [
114 -95.30181,
115 32.35066
116 ]
117 },
118 "properties": {
119 "title": "Downtown Coffee Lounge",
120 "artist": null,
121 "description": "In addition to being the only coffee shop in downtown Tyler, DCL also features regular exhibitions of work by local artists.",
122 "install_date": null,
123 "address": "200 West Erwin Street",
124 "type": "Gallery",
125 "photo_url": null,
126 "photo_credit": null,
127 "last_seen_date": "2012-03-30"
128 }
129 },
130 {
131 "...": "..."
132 }
133 ],
134 "crs": {
135 "type": "name",
136 "properties": {
137 "name": "EPSG:4269"
138 }
139 }
140 }