csv_reader - bruno-beloff/scs_mfr GitHub Wiki

docs > software repositories > scs_mfr > 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.

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 [-a] [-v] [FILENAME]

Options
--version show program's version number and exit
-h, --help show this help message and exit
-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}}]

SEE ALSO

scs_mfr/csv_writer

RESOURCES

JSON Lines