node - bruno-beloff/scs_dev GitHub Wiki
docs > software repositories > scs_dev > commands > manipulating nodes within JSON documents
DESCRIPTION
The node utility is used to extract a node or nodes from within a JSON document. Data is presented as a sequence of documents on stdin, and the extracted node(s) are passed to stdout. Alternatively to stdin, a single JSON document can be read from a file.The extracted node may be a leaf node or an internal node.
By default, only the specified nodes are passed to the output. In the --exclude mode, all nodes are passed to stdout, with the exception of the specified nodes. In the default mode, if no node path is specified, the whole input document is passed to stdout. In the --exclude mode, if no node path is specified, then nothing is output.
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.
Alternatively, if the node is an array or other iterable type, then it may be output as a sequence (a list of items separated by newline characters) according to the -s flag.
SYNOPSIS
node.py [{ [-x] [-a] | -s }] [-f FILE] [-i INDENT] [-v] [SUB_PATH_1 .. SUB_PATH_N]
Options | |
---|---|
--version | show program's version number and exit |
-h, --help | show this help message and exit |
-x, --exclude | include all sub-paths except the named one(s) |
-a, --array | output the sequence of input JSON documents as array |
-s, --sequence | output the contents of the input array node(s) as a sequence |
-f FILENAME, --file=FILENAME | read from FILE instead of stdin |
-i INDENT, --indent=INDENT | pretty-print the output with INDENT |
-v, --verbose | report narrative to stderr |
EXAMPLES
./gases_sampler.py -i10 | ./node.py val
DOCUMENT EXAMPLE - INPUT
{"tag": "scs-ap1-6", "rec": "2018-04-04T14:50:27.641+00:00", "val": {"hmd": 59.6, "tmp": 23.8}}
DOCUMENT EXAMPLE - OUTPUT
{"hmd": 59.6, "tmp": 23.8}