format
Command
The format
command creates a string from the JSON input based on the provided format string.
Usageβ
format [--<format-option>] <format_string>
Parametersβ
Alternatively, a custom format string may be provided to the command:
Parameter | Description | Required? | Default Value |
---|---|---|---|
format_string | Format string * | β |
* The format string may contain placeholders in curly braces that access properties of the JSON object. If a property is not available, it will result in the string null
.
Optionsβ
Option | Description | Required? |
---|---|---|
--json | Return JSON string within a JSON array | β |
--ndjson | Return newline-delimited list of JSON objects | β |
--text | Return text representation of each element | β |
--cytoscape | Return Cytoscape.js string representation | β |
--graphml | Return GraphML string representation | β |
--dot | Return Graphviz DOT string representation | β |
Examplesβ
This first example has a result of [ "b!=d" ]
:
> json {"a":"b", "b": {"c":"d"}} | format {a}!={b.c}
The result of the next command is [ "only select >2<" ]
:
> json {"b": {"c":[0,1,2,3]}} | format only select >{b.c[2]}<
The following command results in [ "only select >2<" ]
:
> json {"b": {"c":[0,1,2,3]}} | format only select >{b.c[2]}<
And the below example has a result of [ "null:null:null" ]
:
> json {} | format {a}:{b.c.d}:{foo.bla[23].test}
This command writes the result of search all
in JSON format to a file named out.json
:
> search all | format --json | write out.json