Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

 
 

Specify the Output Format for Operational Information Requests in a Junos XML Protocol Session

A Junos XML protocol client application can include the format attribute in Junos XML request tags to specify the output format for operational information requests on Junos devices.

A Junos XML protocol client application can request operational information about a device running Junos OS or a device running Junos OS Evolved. The client application emits an <rpc> element that encloses a Junos XML request tag element. The client application can request that the server return the output in the following formats:

  • Junos XML elements (default)

  • Formatted ASCII text

  • JavaScript Object Notation (JSON)

To request the output in a specific format, the client application includes the optional format attribute in the opening operational request tag. The basic syntax is as follows:

The following sections outline how to request a specific format and the response from the server.

XML Format

By default, the Junos XML protocol server returns operational information in XML format. If the client application includes the format="xml" attribute, or if the application omits the format attribute, the server returns the response in XML. The following example requests information for the ge-0/3/0 interface and omits the format attribute.

The Junos XML protocol server returns the response in XML, which is identical to the output displayed in the CLI when you issue an operational mode command and include the | display xml option.

ASCII Text

To request that the Junos XML protocol server return operational information as formatted ASCII text, the client application includes the format="text" or format="ascii" attribute in the opening request tag.

The Junos XML protocol server formats the reply as ASCII text and encloses it in an <output> element. The format="text" and format="ascii" attributes produce identical output.

The following example shows the equivalent operational mode command executed in the CLI:

The formatted ASCII text returned by the Junos XML protocol server is identical to the CLI output except in cases where the output includes disallowed characters such as '<' (less-than sign), '>' (greater-than sign), and '&' (ampersand). The Junos XML protocol server substitutes these characters with the equivalent predefined entity reference of '&lt;', '&gt;', and '&amp;' respectively.

If the Junos XML API does not define a response tag element for the type of output requested by a client application, the Junos XML protocol server returns the reply as formatted ASCII text enclosed in an <output> tag element even if XML-tagged output is requested.

Note:

The content and formatting of data within an <output> tag element are subject to change, so client applications must not depend on them.

JSON Format

To request that the Junos XML protocol server return operational information in JSON format, the client application includes the format="json" attribute in the opening request tag.

The Junos XML protocol server returns JSON data.

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 operational state in compact JSON format, in which only objects that have multiple values are emitted as JSON arrays. 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 | display json command and displays the output in non-compact and compact JSON format.

Non-compact JSON format:

Compact JSON format:

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.