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 Configuration Data in a Junos XML Protocol Session

In a Junos XML protocol session with a device running Junos OS, to request information about a configuration on a routing, switching, or security platform, a client application encloses the <get-configuration> element in an <rpc> tag. The client application can specify the formatting of the configuration data returned by the Junos XML protocol server by setting optional attributes in the <get-configuration> tag.

To request that the Junos XML protocol server return configuration information in Junos XML-tagged output, the client application either includes the format="xml" attribute in the <get-configuration/> tag or opening <get-configuration> tag or omits the attribute completely. The Junos XML protocol server returns Junos XML-tagged output by default, except when the compare attribute is included.

To request that the Junos XML protocol server return configuration information as formatted ASCII text instead of tagging it with Junos XML tag elements, the client application includes the format="text" attribute in the <get-configuration/> tag or opening <get-configuration> tag.

Starting in Junos OS Release 15.1, the client application includes the format="set" attribute in the <get-configuration/> tag or opening <get-configuration> tag to request that the Junos XML protocol server return configuration information as configuration mode set commands instead of Junos XML tag elements. The client application encloses the request in an <rpc> tag element.

Starting in Junos OS Release 14.2, a client application can request that the Junos XML protocol server return configuration information in JavaScript Object Notation (JSON) format. To return configuration data in JSON format instead of tagging it with Junos XML tag elements, the client application includes the format="json" attribute in the <get-configuration/> tag or opening <get-configuration> tag. The client application encloses the request in an <rpc> tag element.

For information about the tag elements to enclose in the <get-configuration> tag element, see Specifying the Scope of Configuration Data to Return in a Junos XML Protocol Session.

Note:

Regardless of which output format they request, client applications use Junos XML tag elements to represent the configuration elements to display. The format attribute controls the format of the Junos XML protocol server’s output only.

When the application requests Junos XML tag elements, the Junos XML protocol server encloses its output in <rpc-reply> and <configuration> tag elements. For information about the attributes in the opening <configuration> tag, see Specifying the Source for Configuration Information Requests in a Junos XML Protocol Session.

When the application requests formatted ASCII output, the Junos XML protocol server formats its response in the same way that the CLI show configuration command displays configuration data—it uses the newline character, tabs, braces, and square brackets to indicate the hierarchical relationships between configuration statements. The server encloses formatted ASCII configuration statements in <rpc-reply> and <configuration-text> tag elements.

When the application requests configuration mode set commands, the Junos XML protocol server formats its response in the same way that the CLI show configuration | display set command displays configuration data. The server encloses the data in <rpc-reply> and <configuration-set> tag elements.

When the application requests JSON format, the Junos XML protocol server encloses the JSON data in <rpc-reply> and <configuration-json> tag elements.

Note:

Starting in Junos OS Release 16.1, devices running Junos OS emit JSON-formatted configuration data using a new default implementation for serialization.

Note:

Starting in Junos OS Releases 16.1R4, 16.2R2, and 17.1R1, integers in Junos OS configuration data emitted in JSON format are not enclosed in quotation marks. In earlier releases, integers in JSON configuration data are treated as strings and enclosed in quotation marks.

The format attribute can be combined with one or more of the following other attributes in the <get-configuration/> tag or opening <get-configuration> tag:

  • compare with the value compare="rollback" and with rollback="0". When you compare the candidate configuration to the active configuration (rollback="0"), you can display the differences in formats other than text by including the appropriate value for the format attribute in the request. You can display the differences in XML format starting in Junos OS Release 15.1R1, and you can display the differences in JSON format starting in Junos OS Release 16.1R1.

  • commit-scripts with a value of commit-scripts="apply" or commit-scripts="apply-no-transients". The commit-scripts="view" attribute returns Junos XML-tagged output by default, even if the format="text" attribute is included, since this is the format that is input to commit scripts.

  • database, which is described in Specifying the Source for Configuration Information Requests in a Junos XML Protocol Session

  • inherit and optionally groups and interface-ranges, which are described in Specifying the Output Format for Configuration Groups and Interface Ranges Using the Junos XML Protocol

It does not make sense to combine the format="text" attribute with the changed attribute (described in Requesting Change Indicators for Configuration Elements Using the Junos XML Protocol) or to include it after requesting an indicator for identifiers (described in Requesting Identifier Indicators for Configuration Elements Using the Junos XML Protocol). The change and identifier indicators appear only in Junos XML-tagged and JSON output.

An application can request Junos-XML tagged output, formatted ASCII text, configuration mode set commands, or JSON output for the entire configuration or any portion of it. For instructions on specifying the amount of data to return, see Specifying the Scope of Configuration Data to Return in a Junos XML Protocol Session.

The following example shows how to request formatted ASCII output from the [edit policy-options] hierarchy level in the candidate configuration.

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
16.1R4
Starting in Junos OS Releases 16.1R4, 16.2R2, and 17.1R1, integers in Junos OS configuration data emitted in JSON format are not enclosed in quotation marks. In earlier releases, integers in JSON configuration data are treated as strings and enclosed in quotation marks.
16.1
Starting in Junos OS Release 16.1, devices running Junos OS emit JSON-formatted configuration data using a new default implementation for serialization.
15.1
Starting in Junos OS Release 15.1, the client application includes the format="set" attribute in the <get-configuration/> tag or opening <get-configuration> tag to request that the Junos XML protocol server return configuration information as configuration mode set commands instead of Junos XML tag elements.