Specify the Output Format for Operational Information Requests in a NETCONF Session
A NETCONF 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 NETCONF 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 specify the format for the RPC output in its
request. By default, the server returns the RPC output in XML format.
To request the output in a specific format, the client application includes the
format attribute in the opening operational request tag. The
syntax is as follows:
<rpc>
<operational-request format="(ascii | json | json-minified | text | xml | xml-genstate-path | xml-minified | xml-xpath)">
<!-- tag elements for options -->
</operational-request>
</rpc>
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.
format Attribute Value |
Description |
|---|---|
|
|
Formatted ASCII text. |
|
|
JSON format. |
|
|
JSON format with unnecessary spaces, tabs, and newlines removed. |
|
|
Formatted ASCII text. |
|
|
Junos XML format. |
|
|
Junos XML format that includes the
|
|
|
Junos XML format with unnecessary spaces, tabs, and newlines removed. |
|
|
Junos XML format that includes the
|
XML Format
By default, the NETCONF server returns operational information in XML format. If a
client application sets the format attribute to
xml or 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.
<rpc>
<get-interface-information>
<brief/>
<interface-name>ge-0/3/0</interface-name>
</get-interface-information>
</rpc>
The NETCONF server returns the information in XML format. The output is identical to
the CLI output when you append the | display xml filter to the
operational mode command.
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"
xmlns:junos="http://xml.juniper.net/junos/25.2R1.9/junos">
<interface-information
xmlns="http://xml.juniper.net/junos/25.2R1.9/junos-interface" junos:style="brief">
<physical-interface>
<name>ge-0/3/0</name>
<admin-status junos:format="Enabled">up</admin-status>
<oper-status>down</oper-status>
<link-level-type>Ethernet</link-level-type>
<mtu>1514</mtu>
<source-filtering>disabled</source-filtering>
<speed>1000mbps</speed>
<bpdu-error>none</bpdu-error>
<l2pt-error>none</l2pt-error>
<loopback>disabled</loopback>
<if-flow-control>enabled</if-flow-control>
<if-auto-negotiation>enabled</if-auto-negotiation>
<if-remote-fault>online</if-remote-fault>
<if-device-flags>
<ifdf-present/>
<ifdf-running/>
<ifdf-down/>
</if-device-flags>
<if-config-flags>
<iff-hardware-down/>
<iff-snmp-traps/>
<internal-flags>0x4000</internal-flags>
</if-config-flags>
<if-media-flags>
<ifmf-none/>
</if-media-flags>
</physical-interface>
</interface-information>
</rpc-reply>
xml-minified Format
Operational command RPCs also support returning XML output in minified format, which
omits unnecessary spaces, tabs, and newlines. To request minified XML output in
supported releases, include the format="xml-minified" attribute in
the opening request tag. For example:
<rpc>
<get-interface-information format="xml-minified">
<brief/>
<interface-name>ge-0/3/0</interface-name>
</get-interface-information>
</rpc>
The NETCONF server returns the information in minified XML format.
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns:junos="http://xml.juniper.net/junos/25.2R1.9/junos"> <interface-information xmlns="http://xml.juniper.net/junos/25.2R1.9/junos-interface" junos:style="brief"><physical-interface><name>ge-0/3/0</name><admin-status junos:format="Enabled">up</admin-status><oper-status>down</oper-status><link-level-type>Ethernet</link-level-type><mtu>1514</mtu><source-filtering>disabled</source-filtering><speed>1000mbps</speed><bpdu-error>none</bpdu-error><l2pt-error>none</l2pt-error><loopback>disabled</loopback><if-flow-control>enabled</if-flow-control><if-auto-negotiation>enabled</if-auto-negotiation><if-remote-fault>online</if-remote-fault><if-device-flags><ifdf-present/><ifdf-running/><ifdf-down/></if-device-flags><if-config-flags><iff-hardware-down/><iff-snmp-traps/><internal-flags>0x4000</internal-flags></if-config-flags><if-media-flags><ifmf-none/></if-media-flags></physical-interface></interface-information></rpc-reply>
xml-genstate-path Format
Junos devices expose some Junos XML RPC responses in telemetry under the genstate
origin (genstate:). A gNMI telemetry collector can subscribe to
resource paths published in the genstate YANG modules to query for
the corresponding state data on a device. The xml-genstate-path
format returns the command output in XML. The output includes the
junos:genstate-path attribute for every emitted tag that is
available for subscription. The attribute value is that node's
genstate subscription path.
For example, the following RPC is equivalent to the show system commit
revision | display xml genstate-path operational command.
<rpc><get-commit-revision-information format="xml-genstate-path"/></rpc>
When you specify format="xml-genstate-path", the XML output shows
the available genstate paths that a telemetry client can use to
subscribe to the corresponding state date.
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns:junos="http://xml.juniper.net/junos/26.2R1.12-EVO/junos"> <commit-revision-information junos:genstate-path="genstate:/genstate/commit-revision-information"> <revision junos:genstate-path="genstate:/genstate/commit-revision-information/revision">re0-1778619027-1</revision> </commit-revision-information> </rpc-reply>
xml-xpath Format
Many client applications use XPath to parse or reference nodes in Junos XML data. The
xml-xpath format returns XML output that includes the
junos:data-xpath attribute for every tag. The attribute value
is the XPath expression that selects that specific node. You can use this attribute
to quickly retrieve the correct XPath expression for a given element.
The following example executes the
<get-commit-revision-information> RPC and requests the
xml-xpath format:
<rpc><get-commit-revision-information format="xml-xpath"/></rpc>
The xml-xpath format displays the XPath expression for each node in
the output.
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns:junos="http://xml.juniper.net/junos/26.2R1.12-EVO/junos"> <commit-revision-information junos:data-xpath="/commit-revision-information"> <revision junos:data-xpath="/commit-revision-information/revision">re0-1778619027-1</revision> </commit-revision-information> </rpc-reply>
ASCII Format
To request that the NETCONF server return operational information as formatted ASCII
text, the client application includes the format="text" or
format="ascii" attribute in the opening request tag.
<rpc>
<get-interface-information format="(text | ascii)">
<brief/>
<interface-name>ge-0/3/0</interface-name>
</get-interface-information>
</rpc>
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.
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"
xmlns:junos="http://xml.juniper.net/junos/25.2R1.9/junos">
<output>
Physical interface: ge-0/3/0, Enabled, Physical link is Down
Link-level type: Ethernet, MTU: 1514, Speed: 1000mbps, Loopback: Disabled,
Source filtering: Disabled, Flow control: Enabled, Auto-negotiation: Enabled,
Remote fault: Online
Device flags : Present Running Down
Interface flags: Hardware-Down SNMP-Traps Internal: 0x4000
Link flags : None
</output>
</rpc-reply>
The following example shows the equivalent operational mode command executed in the CLI:
user@host> show interfaces ge-0/3/0 brief Physical interface: ge-0/3/0, Enabled, Physical link is Down Link-level type: Ethernet, MTU: 1514, Speed: 1000mbps, Loopback: Disabled, Source filtering: Disabled, Flow control: Enabled, Auto-negotiation: Enabled, Remote fault: Online Device flags : Present Running Down Interface flags: Hardware-Down SNMP-Traps Internal: 0x4000 Link flags : None
The formatted ASCII text returned by the NETCONF server is identical to the CLI output except in cases where the output includes disallowed characters. Disallowed characters include '<' (less-than sign), '>' (greater-than sign), and '&' (ampersand). The NETCONF server substitutes these characters with the equivalent predefined entity reference of '<', '>', and '&' 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.
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
A client application can request 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.
<rpc>
<get-interface-information format="json">
<brief/>
<interface-name>cbp0</interface-name>
</get-interface-information>
</rpc>
When the client application includes the format="json" attribute in
the request tag, the NETCONF server returns JSON data.
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"
xmlns:junos="http://xml.juniper.net/junos/25.2R1.9/junos">
{
"interface-information" : [
{
"physical-interface" : [
{
"name" : [
{
"data" : "cbp0"
}
],
"admin-status" : [
{
"data" : "up",
"attributes" : {"junos:format" : "Enabled"}
}
],
"oper-status" : [
{
"data" : "up"
}
],
"if-type" : [
{
"data" : "Ethernet"
}
],
"link-level-type" : [
{
"data" : "Ethernet"
}
],
"mtu" : [
{
"data" : "9192"
}
],
"speed" : [
{
"data" : "Unspecified"
}
],
"clocking" : [
{
"data" : "Unspecified"
}
],
"if-device-flags" : [
{
"ifdf-present" : [
{
"data" : [null]
}
],
"ifdf-running" : [
{
"data" : [null]
}
]
}
],
"ifd-specific-config-flags" : [
{
}
],
"if-config-flags" : [
{
"iff-snmp-traps" : [
{
"data" : [null]
}
]
}
]
}
]
}
]
}
</rpc-reply>
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. Compact JSON format emits JSON arrays only
for objects that have multiple values. To configure the device to emit compact JSON
format, configure the compact statement at the [edit system
export-format state-data json] hierarchy level.
NETCONF clients can also request operational command RPC output in minified JSON
format, which omits unnecessary spaces, tabs, and newlines. To request minified JSON
output in supported releases, include the format="json-minified"
attribute in the opening request tag. For example:
<rpc>
<get-interface-information format="json-minified">
<brief/>
<interface-name>cbp0</interface-name>
</get-interface-information>
</rpc>
The NETCONF server returns the information in minified JSON format.
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns:junos="http://xml.juniper.net/junos/25.2R1.9/junos">
{"interface-information":[{"physical-interface":[{"name":[{"data":"cbp0"}],"admin-status":[{"data":"up","attributes":{"junos:format":"Enabled"}}],"oper-status":[{"data":"up"}],"if-type":[{"data":"Ethernet"}],"link-level-type":[{"data":"Ethernet"}],"mtu":[{"data":"9192"}],"speed":[{"data":"Unspecified"}],"clocking":[{"data":"Unspecified"}],"if-device-flags":[{"ifdf-present":[{"data":[null]}],"ifdf-running":[{"data":[null]}]}],"ifd-specific-config-flags":[{}],"if-config-flags":[{"iff-snmp-traps":[{"data":[null]}]}]}]}]}</rpc-reply>
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.
format attribute for operational RPCs includes the
xml-genstate-path and xml-xpath
options.compact statement at the
[edit system export-format state-data json] hierarchy
level.