csv_reader - bruno-beloff/scs_dev GitHub Wiki
docs > software repositories > scs_dev > commands > file-based data management
DESCRIPTION
The csv_reader utility is used to convert data from comma-separated value (CSV) format to JSON format.
The names of columns given in the CSV header row indicate paths into the JSON document: dictionary fields are separated from their container by a period ('.') character, and JSON array members separated from their container by a colon (':') character.
The first row of the CSV file (or stdin input) is assumed to be a header row. If there are more columns in the body of the CSV than in the header, excess values are ignored. Header cells may not be empty.
By default, output is in the form of a sequence of JSON documents, separated by newlines. If the array (-a) option is selected, output is in the form of a JSON array - the output opens with a '[' character, documents are separated by the ',' character, and the output is terminated by a ']' character.
SYNOPSIS
csv_reader.py [-s] [-n] [-l LIMIT] [-a] [-v] [FILENAME_1 .. FILENAME_N]
Options | |
---|---|
--version | show program's version number and exit |
-h, --help | show this help message and exit |
-s, --string | interpret all values as strings |
-n, --nullify | convert empty or "NULL" strings to nulls |
-l LIMIT, --limit=LIMIT | output a maximum of LIMIT rows |
-a, --array | output JSON documents as array instead of a sequence |
-v, --verbose | report narrative to stderr |
EXAMPLES
./csv_reader.py sht.csv
DOCUMENT EXAMPLE - INPUT
tag,rec,val.hmd,val.tmp scs-ap1-6,2018-04-04T14:50:38.394+00:00,59.7,23.8
scs-ap1-6,2018-04-04T14:55:38.394+00:00,59.8,23.9
DOCUMENT EXAMPLE - OUTPUT
Sequence mode:
{"tag": "scs-ap1-6", "rec": "2018-04-04T14:50:38.394+00:00", "val": {"hmd": 59.7, "tmp": 23.8}}
{"tag": "scs-ap1-6", "rec": "2018-04-04T14:55:38.394+00:00", "val": {"hmd": 59.8, "tmp": 23.9}}
Array mode:
[{"tag": "scs-ap1-6", "rec": "2018-04-04T14:50:38.394+00:00", "val": {"hmd": 59.7, "tmp": 23.8}}, {"tag": "scs-ap1-6", "rec": "2018-04-04T14:55:38.394+00:00", "val": {"hmd": 59.8, "tmp": 23.9}}]