Output Formats for Show Commands
The response from NX-OS show commands can be displayed in various formats. The default command output is plain text, with tables formatted using spaces to align columns. This type of output is easily readable, but may not be convenient as the input for automation scripts. For many show commands, you can choose to have the output delivered in XML format. For any command that supports XML output, a further option is JSON output.
Checking for XML/JSON Support
To determine whether a show command supports XML output, pipe the output to | validate-xml
, as in this example:
# show version | validate-xml
Schema version is 1.0
The output is valid.
To determine whether a show command supports JSON output, pipe the output to | validate-json
, as in this example:
# show version | validate-json
Schema version is 9.3.3.
The JSON output is valid.
Specifying XML or JSON Output
To receive the actual command output in XML format, pipe the output to | xml
, as in this example:
# show version | xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<nf:rpc-reply xmlns="http://www.cisco.com/nxos:1.0:sysmgrcli" xmlns:nf="urn:ietf:params:xml:ns:netconf:base:1.0">
<nf:data>
<show>
<version>
[ output cropped ]
</version>
</show>
</nf:data>
</nf:rpc-reply>
]]>]]>
To receive the command output in JSON format, pipe the output to | json
. In this case, the JSON output is delivered as a minified JSON block. For a more human-readable presentation, pipe the output
to | json-pretty
, which delivers a visually structured and indented JSON output.
Testing Commands in the NX-OS Sandbox
Cisco DevNet maintains simulator sandboxes for Cisco Nexus switches and many other Cisco products. You can test NX-OS commands and view the resulting command output using the Open NX-OS Programmability lab at the following URL: