Skip to main content

format Command

The format command creates a string from the JSON input based on the provided format string.

Usage

format [--<format-option>] <format_string>

Options

The format command supports some predefined formats, which can be utilized using the following options:

OptionDescription
--jsonCreates a JSON string and returns it within a JSON array.
--ndjsonCreates a JSON object for each element, with line element per line in the output.
--textCreates a text representation of each element.
--cytoscapeCreates a string representation in Cytoscape.js format
--graphmlCreates a string representation in GraphML format
--dotCreates a string representation in Graphviz DOT format

Parameters

Alternatively, a custom format string may be provided to the command:

ParameterDescriptionRequired?Default Value
format_stringFormat string *N/A

* 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.

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

Contact Us