Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

 
 

Map Junos OS Command Output to JSON in the CLI

The Junos operating system (Junos OS) natively supports XML for the operation and configuration of devices running Junos OS, and the Junos OS command-line interface (CLI) and the Junos OS infrastructure communicate using XML. When you issue an operational command or display the configuration in the CLI, the CLI converts the output from XML into a readable text format for display.

Starting in Junos OS Release 14.2, devices running Junos OS also support a JavaScript Object Notation (JSON) representation of the operational command output and the Junos OS configuration hierarchy. On the Junos OS CLI, to display the command output or configuration in JSON instead of in the default formatted ASCII text, append the | display json option to the command.

The following example executes the show chassis hardware command and displays the output in JSON format. The response is identical to the NETCONF or Junos XML protocol server response for the <get-chassis-inventory format="json"> RPC request.

Starting in Junos OS Release 16.1, Junos OS uses a new default implementation for serialization for configuration data emitted in JSON format. The new default, ietf, is as defined in the following Internet drafts:

In earlier releases, the default is verbose, which emits all objects as JSON arrays. You can configure the default export format for JSON configuration data by configuring the appropriate statement at the [edit system export-format json] hierarchy level. You can configure the verbose statement starting in Junos OS Release 16.1R1, even though the statement is not exposed in the Junos OS CLI until a later release.

Starting in Junos OS Release 17.3R1, devices running Junos OS support emitting the device’s operational state in compact JSON format, in which only objects that have multiple values are emitted as JSON arrays. To configure the device to emit compact JSON format, configure the compact statement at the [edit system export-format state-data json] hierarchy level.

The following example executes the show system uptime command and displays the output in non-compact and compact JSON format.

Non-compact JSON format:

The compact JSON format for the same command is:

Release History Table
Release
Description
17.3R1
Starting in Junos OS Release 17.3R1, devices running Junos OS support emitting the device’s operational state in compact JSON format, in which only objects that have multiple values are emitted as JSON arrays.
16.1
Starting in Junos OS Release 16.1, Junos OS uses a new default implementation for serialization for configuration data emitted in JSON format.