Skip to main content
Version: 4.0.5

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:

ParameterDescriptionRequired?Default Value
format_stringFormat 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

OptionDescriptionRequired?
--jsonReturn JSON string within a JSON array
--ndjsonReturn newline-delimited list of JSON objects
--textReturn text representation of each element
--cytoscapeReturn Cytoscape.js string representation
--graphmlReturn GraphML string representation
--dotReturn 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