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