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

Junos OS and Junos OS Evolved natively support XML for the operation and configuration of Junos devices. The CLI and the 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.

Junos devices also support a JavaScript Object Notation (JSON) representation of the operational command output and the configuration hierarchy. 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 in the CLI.

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.

You can configure how a Junos device emits configuration data in JSON format. To configure the default export format, include the appropriate statement at the [edit system export-format json] hierarchy level. You can configure the JSON export format as one of the following:

By default, Junos devices emit JSON-formatted state data in non-compact format, which emits all objects as JSON arrays. In Junos OS Release 24.2 and earlier and Junos OS Evolved Release 24.2 and earlier, Junos devices support emitting the device’s state data 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 in supported releases, 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 both non-compact and compact JSON format.

The following output shows the non-compact JSON format:

The output for the same command in compact JSON format is:

Change History Table

Feature support is determined by the platform and release you are using. Use Feature Explorer to determine if a feature is supported on your platform.

Release
Description
24.4R1 & 24.4R1-EVO
Starting in Junos OS Release 24.4R1 and Junos OS Evolved Release 24.4R1, we've deprecated the compact statement at the [edit system export-format state-data json] hierarchy level.