Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

 
 

Specifying the Output Format for Operational Information Requests in a NETCONF Session

In a NETCONF session, to request information about a device running Junos OS, a client application emits an <rpc> element that encloses a Junos XML request tag element. By setting the optional format attribute in the opening operational request tag, the client application can specify the format of the output returned by the NETCONF server. Information can be returned as formatted ASCII text, JavaScript Object Notation (JSON), or XML-tagged format. The syntax is as follows:

Table 1 describes the available formats. Minified formats remove characters that are not required for computer processing, for example, spaces, tabs, and newlines. Minified formats decrease the size of the data, and as a result, can reduce transport costs and data delivery and processing times.

Table 1: Operational RPC Output Formats
format Attribute Value Description
ascii Formatted ASCII text
json JavaScript Object Notation (JSON)
json-minified JSON format with unnecessary spaces, tabs, and newlines removed
text Formatted ASCII text
xml Junos XML-tagged format
xml-minified Junos XML-tagged format with unnecessary spaces, tabs, and newlines removed

XML Format

By default, the NETCONF server returns operational information in XML-tagged format. If the value of the format attribute is set to xml or if the format attribute is omitted, the server returns the response in XML. The following example requests information for the ge-0/3/0 interface. The format attribute is omitted.

The NETCONF server returns the information in XML-tagged format, which is identical to the output displayed in the CLI when you include the | display xml option after the operational mode command.

Starting in Junos OS Release 21.1R1, operational command RPCs support returning XML output in minified format, in which unnecessary spaces, tabs, and newlines are omitted. To request minified XML output, include the format="xml-minified" attribute in the opening request tag. For example:

The NETCONF server returns the information in minified XML format.

JSON Format

Starting in Junos OS Release 14.2, you can display operational and configuration data in JSON format. To request that the NETCONF server return operational information in JSON format, the client application includes the format="json" attribute in the opening request tag. The client application encloses the request in an <rpc> element.

When the client application includes the format="json" attribute in the request tag, the NETCONF server formats the reply using JSON.

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.

Starting in Junos OS Release 21.1R1, operational command RPCs support returning JSON output in minified format, in which unnecessary spaces, tabs, and newlines are omitted. To request minified JSON output, include the format="json-minified" attribute in the opening request tag. For example:

The NETCONF server returns the information in minified JSON format.

ASCII Format

To request that the NETCONF server return operational information as formatted ASCII text instead of tagging it with Junos XML tag elements, the client application includes the format="text" or format="ascii" attribute in the opening request tag. The client application encloses the request in an <rpc> tag element.

When the client application includes the format="text" or format="ascii" attribute in the request tag, the NETCONF server formats the reply as ASCII text and encloses it in an <output> tag 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 NETCONF 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 NETCONF 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 NETCONF server returns the reply as formatted ASCII text enclosed in an <output> tag element, even if XML-tagged output is requested.

For information about the <output> tag element, see the Junos XML API Operational Developer Reference.

Note:

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

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.
14.2
Starting in Junos OS Release 14.2, you can display operational and configuration data in JSON format.