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 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 | text | xml | xml-genstate-path | xml-xpath)">
<!-- tag elements for options -->
</operational-request>
</rpc>
Table 1 describes the available formats.
format Attribute Value |
Description |
|---|---|
|
|
Formatted ASCII text. |
|
|
JSON format. |
|
|
Formatted ASCII text. |
|
|
Junos XML format. |
|
|
Junos XML format that includes the
|
|
|
Junos XML format that includes the
|
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 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 Junos XML protocol server returns the response 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:junos="http://xml.juniper.net/junos/24.4R1/junos">
<interface-information
xmlns="http://xml.juniper.net/junos/24.4R1/junos-interface" junos:style="brief">
<physical-interface>
<name>ge-0/3/0</name>
<admin-status junos:format="Enabled">up</admin-status>
<oper-status>up</oper-status>
<link-level-type>Ethernet</link-level-type>
<mtu>1514</mtu>
<sonet-mode>LAN-PHY</sonet-mode>
<mru>1522</mru>
<source-filtering>disabled</source-filtering>
<speed>1000mbps</speed>
<eth-switch-error>none</eth-switch-error>
<remote-bounce>none</remote-bounce>
<bpdu-error>none</bpdu-error>
<ld-pdu-error>none</ld-pdu-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>
<pad-to-minimum-frame-size>Disabled</pad-to-minimum-frame-size>
<if-device-flags>
<ifdf-present/>
<ifdf-running/>
</if-device-flags>
<ifd-specific-config-flags>
<internal-flags>0x100000</internal-flags>
</ifd-specific-config-flags>
<if-config-flags>
<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: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: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 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.
<rpc>
<get-interface-information format="(text | ascii)">
<brief/>
<interface-name>ge-0/3/0</interface-name>
</get-interface-information>
</rpc>
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.
<rpc-reply xmlns:junos="http://xml.juniper.net/junos/24.4R1/junos"> <output> Physical interface: ge-0/3/0, Enabled, Physical link is Up Link-level type: Ethernet, MTU: 1514, MRU: 1522, LAN-PHY mode, Speed: 1000mbps, Loopback: Disabled, Source filtering: Disabled, Flow control: Enabled, Auto-negotiation: Enabled, Remote fault: Online Device flags : Present Running Interface Specific flags: Internal: 0x100000 Interface flags: 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 Up Link-level type: Ethernet, MTU: 1514, MRU: 1522, LAN-PHY mode, Speed: 1000mbps, Loopback: Disabled, Source filtering: Disabled, Flow control: Enabled, Auto-negotiation: Enabled, Remote fault: Online Device flags : Present Running Interface Specific flags: Internal: 0x100000 Interface flags: SNMP-Traps Internal: 0x4000 Link flags : None
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 '<', '>', 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 Junos XML protocol 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
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.
<rpc>
<get-interface-information format="json">
<brief/>
<interface-name>cbp0</interface-name>
</get-interface-information>
</rpc>
The Junos XML protocol server returns JSON data.
<rpc-reply xmlns:junos="http://xml.juniper.net/junos/24.4R1/junos">
{
"interface-information" : [
{
"attributes" : {"xmlns" : "http://xml.juniper.net/junos/24.4R1/junos-interface",
"junos:style" : "brief"
},
"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" : "1514"
}
],
"speed" : [
{
"data" : "Unspecified"
}
],
"clocking" : [
{
"data" : "Unspecified"
}
],
"if-device-flags" : [
{
"ifdf-present" : [
{
"data" : [null]
}
],
"ifdf-running" : [
{
"data" : [null]
}
]
}
],
"ifd-specific-config-flags" : [
{
"internal-flags" : [
{
"data" : "0x0"
}
]
}
],
"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, 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.
user@host# set system export-format state-data json compact user@host# commit
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:
{
"system-uptime-information" : [
{
"attributes" : {"xmlns" : "http://xml.juniper.net/junos/18.1R1/junos"},
"current-time" : [
{
"date-time" : [
{
"data" : "2018-05-15 13:43:46 PDT",
"attributes" : {"junos:seconds" : "1526417026"}
}
]
}
],
"time-source" : [
{
"data" : " NTP CLOCK "
}
],
"system-booted-time" : [
{
"date-time" : [
{
"data" : "2018-05-15 10:57:02 PDT",
"attributes" : {"junos:seconds" : "1526407022"}
}
],
"time-length" : [
{
"data" : "02:46:44",
"attributes" : {"junos:seconds" : "10004"}
}
]
}
],
"protocols-started-time" : [
{
"date-time" : [
{
"data" : "2018-05-15 10:59:33 PDT",
"attributes" : {"junos:seconds" : "1526407173"}
}
],
"time-length" : [
{
"data" : "02:44:13",
"attributes" : {"junos:seconds" : "9853"}
}
]
}
],
"last-configured-time" : [
{
"date-time" : [
{
"data" : "2018-05-02 17:57:44 PDT",
"attributes" : {"junos:seconds" : "1525309064"}
}
],
"time-length" : [
{
"data" : "1w5d 19:46",
"attributes" : {"junos:seconds" : "1107962"}
}
],
"user" : [
{
"data" : "admin"
}
]
}
],
"uptime-information" : [
{
"date-time" : [
{
"data" : "1:43PM",
"attributes" : {"junos:seconds" : "1526417026"}
}
],
"up-time" : [
{
"data" : "2:47",
"attributes" : {"junos:seconds" : "10034"}
}
],
"active-user-count" : [
{
"data" : "1",
"attributes" : {"junos:format" : "1 user"}
}
],
"load-average-1" : [
{
"data" : "0.49"
}
],
"load-average-5" : [
{
"data" : "0.19"
}
],
"load-average-15" : [
{
"data" : "0.10"
}
]
}
]
}
]
}
Compact JSON format:
{
"system-uptime-information" :
{
"current-time" :
{
"date-time" : "2018-05-15 13:49:56 PDT"
},
"time-source" : " NTP CLOCK ",
"system-booted-time" :
{
"date-time" : "2018-05-15 10:57:02 PDT",
"time-length" : "02:52:54"
},
"protocols-started-time" :
{
"date-time" : "2018-05-15 10:59:33 PDT",
"time-length" : "02:50:23"
},
"last-configured-time" :
{
"date-time" : "2018-05-15 13:49:40 PDT",
"time-length" : "00:00:16",
"user" : "admin"
},
"uptime-information" :
{
"date-time" : "1:49PM",
"up-time" : "2:53",
"active-user-count" : "1",
"load-average-1" : "0.00",
"load-average-5" : "0.06",
"load-average-15" : "0.06"
}
}
}
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.