draft-ietf-netmod-yang-json-04.txt | draft-ietf-netmod-yang-json-05.txt | |||
---|---|---|---|---|
NETMOD Working Group L. Lhotka | NETMOD Working Group L. Lhotka | |||
Internet-Draft CZ.NIC | Internet-Draft CZ.NIC | |||
Intended status: Standards Track June 12, 2015 | Intended status: Standards Track September 10, 2015 | |||
Expires: December 14, 2015 | Expires: March 13, 2016 | |||
JSON Encoding of Data Modeled with YANG | JSON Encoding of Data Modeled with YANG | |||
draft-ietf-netmod-yang-json-04 | draft-ietf-netmod-yang-json-05 | |||
Abstract | Abstract | |||
This document defines encoding rules for representing configuration, | This document defines encoding rules for representing configuration, | |||
state data, RPC input and output parameters, and notifications | state data, RPC operation or action input and output parameters, and | |||
defined using YANG as JavaScript Object Notation (JSON) text. | notifications defined using YANG as JavaScript Object Notation (JSON) | |||
text. | ||||
Status of This Memo | Status of This Memo | |||
This Internet-Draft is submitted in full conformance with the | This Internet-Draft is submitted in full conformance with the | |||
provisions of BCP 78 and BCP 79. | provisions of BCP 78 and BCP 79. | |||
Internet-Drafts are working documents of the Internet Engineering | Internet-Drafts are working documents of the Internet Engineering | |||
Task Force (IETF). Note that other groups may also distribute | Task Force (IETF). Note that other groups may also distribute | |||
working documents as Internet-Drafts. The list of current Internet- | working documents as Internet-Drafts. The list of current Internet- | |||
Drafts is at http://datatracker.ietf.org/drafts/current/. | Drafts is at http://datatracker.ietf.org/drafts/current/. | |||
Internet-Drafts are draft documents valid for a maximum of six months | Internet-Drafts are draft documents valid for a maximum of six months | |||
and may be updated, replaced, or obsoleted by other documents at any | and may be updated, replaced, or obsoleted by other documents at any | |||
time. It is inappropriate to use Internet-Drafts as reference | time. It is inappropriate to use Internet-Drafts as reference | |||
material or to cite them other than as "work in progress." | material or to cite them other than as "work in progress." | |||
This Internet-Draft will expire on December 14, 2015. | This Internet-Draft will expire on March 13, 2016. | |||
Copyright Notice | Copyright Notice | |||
Copyright (c) 2015 IETF Trust and the persons identified as the | Copyright (c) 2015 IETF Trust and the persons identified as the | |||
document authors. All rights reserved. | document authors. All rights reserved. | |||
This document is subject to BCP 78 and the IETF Trust's Legal | This document is subject to BCP 78 and the IETF Trust's Legal | |||
Provisions Relating to IETF Documents | Provisions Relating to IETF Documents | |||
(http://trustee.ietf.org/license-info) in effect on the date of | (http://trustee.ietf.org/license-info) in effect on the date of | |||
publication of this document. Please review these documents | publication of this document. Please review these documents | |||
carefully, as they describe your rights and restrictions with respect | carefully, as they describe your rights and restrictions with respect | |||
to this document. Code Components extracted from this document must | to this document. Code Components extracted from this document must | |||
include Simplified BSD License text as described in Section 4.e of | include Simplified BSD License text as described in Section 4.e of | |||
the Trust Legal Provisions and are provided without warranty as | the Trust Legal Provisions and are provided without warranty as | |||
described in the Simplified BSD License. | described in the Simplified BSD License. | |||
Table of Contents | Table of Contents | |||
1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . 2 | 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . 2 | |||
2. Terminology and Notation . . . . . . . . . . . . . . . . . . 3 | 2. Terminology and Notation . . . . . . . . . . . . . . . . . . 3 | |||
3. Validation of JSON-encoded | 3. Properties of the JSON Encoding . . . . . . . . . . . . . . . 4 | |||
Instance Data . . . . . . . . . . . . . . . . . . . . . . . . 4 | ||||
4. Names and Namespaces . . . . . . . . . . . . . . . . . . . . 4 | 4. Names and Namespaces . . . . . . . . . . . . . . . . . . . . 4 | |||
5. Encoding of YANG Data Node Instances . . . . . . . . . . . . 6 | 5. Encoding of YANG Data Node Instances . . . . . . . . . . . . 6 | |||
5.1. The "leaf" Data Node . . . . . . . . . . . . . . . . . . 7 | 5.1. The "leaf" Data Node . . . . . . . . . . . . . . . . . . 7 | |||
5.2. The "container" Data Node . . . . . . . . . . . . . . . . 7 | 5.2. The "container" Data Node . . . . . . . . . . . . . . . . 7 | |||
5.3. The "leaf-list" Data Node . . . . . . . . . . . . . . . . 7 | 5.3. The "leaf-list" Data Node . . . . . . . . . . . . . . . . 7 | |||
5.4. The "list" Data Node . . . . . . . . . . . . . . . . . . 8 | 5.4. The "list" Data Node . . . . . . . . . . . . . . . . . . 8 | |||
5.5. The "anydata" Data Node . . . . . . . . . . . . . . . . . 9 | 5.5. The "anydata" Data Node . . . . . . . . . . . . . . . . . 9 | |||
5.6. The "anyxml" Data Node . . . . . . . . . . . . . . . . . 10 | 5.6. The "anyxml" Data Node . . . . . . . . . . . . . . . . . 10 | |||
6. The Mapping of YANG Data Types to JSON Values . . . . . . . . 10 | 6. Representing YANG Data Types in JSON Values . . . . . . . . . 10 | |||
6.1. Numeric Types . . . . . . . . . . . . . . . . . . . . . . 10 | 6.1. Numeric Types . . . . . . . . . . . . . . . . . . . . . . 10 | |||
6.2. The "string" Type . . . . . . . . . . . . . . . . . . . . 11 | 6.2. The "string" Type . . . . . . . . . . . . . . . . . . . . 11 | |||
6.3. The "boolean" Type . . . . . . . . . . . . . . . . . . . 11 | 6.3. The "boolean" Type . . . . . . . . . . . . . . . . . . . 11 | |||
6.4. The "enumeration" Type . . . . . . . . . . . . . . . . . 11 | 6.4. The "enumeration" Type . . . . . . . . . . . . . . . . . 11 | |||
6.5. The "bits" Type . . . . . . . . . . . . . . . . . . . . . 11 | 6.5. The "bits" Type . . . . . . . . . . . . . . . . . . . . . 11 | |||
6.6. The "binary" Type . . . . . . . . . . . . . . . . . . . . 11 | 6.6. The "binary" Type . . . . . . . . . . . . . . . . . . . . 11 | |||
6.7. The "leafref" Type . . . . . . . . . . . . . . . . . . . 11 | 6.7. The "leafref" Type . . . . . . . . . . . . . . . . . . . 12 | |||
6.8. The "identityref" Type . . . . . . . . . . . . . . . . . 11 | 6.8. The "identityref" Type . . . . . . . . . . . . . . . . . 12 | |||
6.9. The "empty" Type . . . . . . . . . . . . . . . . . . . . 12 | 6.9. The "empty" Type . . . . . . . . . . . . . . . . . . . . 12 | |||
6.10. The "union" Type . . . . . . . . . . . . . . . . . . . . 13 | 6.10. The "union" Type . . . . . . . . . . . . . . . . . . . . 13 | |||
6.11. The "instance-identifier" Type . . . . . . . . . . . . . 13 | 6.11. The "instance-identifier" Type . . . . . . . . . . . . . 14 | |||
7. I-JSON Compliance . . . . . . . . . . . . . . . . . . . . . . 14 | 7. I-JSON Compliance . . . . . . . . . . . . . . . . . . . . . . 14 | |||
8. Security Considerations . . . . . . . . . . . . . . . . . . . 15 | 8. Security Considerations . . . . . . . . . . . . . . . . . . . 15 | |||
9. Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . 15 | 9. Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . 15 | |||
10. References . . . . . . . . . . . . . . . . . . . . . . . . . 15 | 10. References . . . . . . . . . . . . . . . . . . . . . . . . . 15 | |||
10.1. Normative References . . . . . . . . . . . . . . . . . . 15 | 10.1. Normative References . . . . . . . . . . . . . . . . . . 15 | |||
10.2. Informative References . . . . . . . . . . . . . . . . . 16 | 10.2. Informative References . . . . . . . . . . . . . . . . . 16 | |||
Appendix A. A Complete Example . . . . . . . . . . . . . . . . . 16 | Appendix A. A Complete Example . . . . . . . . . . . . . . . . . 16 | |||
Appendix B. Change Log . . . . . . . . . . . . . . . . . . . . . 18 | Appendix B. Change Log . . . . . . . . . . . . . . . . . . . . . 18 | |||
B.1. Changes Between Revisions -03 and -04 . . . . . . . . . . 18 | B.1. Changes Between Revisions -04 and -05 . . . . . . . . . . 18 | |||
B.2. Changes Between Revisions -02 and -03 . . . . . . . . . . 19 | B.2. Changes Between Revisions -03 and -04 . . . . . . . . . . 18 | |||
B.3. Changes Between Revisions -01 and -02 . . . . . . . . . . 19 | B.3. Changes Between Revisions -02 and -03 . . . . . . . . . . 19 | |||
B.4. Changes Between Revisions -00 and -01 . . . . . . . . . . 19 | B.4. Changes Between Revisions -01 and -02 . . . . . . . . . . 19 | |||
Author's Address . . . . . . . . . . . . . . . . . . . . . . . . 19 | B.5. Changes Between Revisions -00 and -01 . . . . . . . . . . 19 | |||
Author's Address . . . . . . . . . . . . . . . . . . . . . . . . 20 | ||||
1. Introduction | 1. Introduction | |||
The NETCONF protocol [RFC6241] uses XML [W3C.REC-xml-20081126] for | The NETCONF protocol [RFC6241] uses XML [W3C.REC-xml-20081126] for | |||
encoding data in its Content Layer. Other management protocols might | encoding data in its Content Layer. Other management protocols might | |||
want to use other encodings while still benefiting from using YANG | want to use other encodings while still benefiting from using YANG | |||
[I-D.ietf-netmod-rfc6020bis] as the data modeling language. | [I-D.ietf-netmod-rfc6020bis] as the data modeling language. | |||
For example, the RESTCONF protocol [I-D.ietf-netconf-restconf] | For example, the RESTCONF protocol [I-D.ietf-netconf-restconf] | |||
supports two encodings: XML (media type "application/yang.data+xml") | supports two encodings: XML (media type "application/yang.data+xml") | |||
and JSON (media type "application/yang.data+json). | and JSON (media type "application/yang.data+json). | |||
The specification of YANG 1.1 data modelling language | The specification of YANG 1.1 data modelling language | |||
[I-D.ietf-netmod-rfc6020bis] defines only XML encoding for data | [I-D.ietf-netmod-rfc6020bis] defines only XML encoding for data | |||
instances, i.e., contents of configuration datastores, state data, | instances, i.e., contents of configuration datastores, state data, | |||
RFC input and output parameters, and event notifications. The aim of | RPC operation or action input and output parameters, and event | |||
this document is to define rules for encoding the same data as | notifications. The aim of this document is to define rules for | |||
JavaScript Object Notation (JSON) text [RFC7159]. | encoding the same data as JavaScript Object Notation (JSON) | |||
text [RFC7159]. | ||||
In order to achieve maximum interoperability while allowing | ||||
implementations to use a variety of available JSON parsers, the JSON | ||||
encoding rules follow, as much as possible, the constraints of the | ||||
I-JSON restricted profile [RFC7493]. Section 7 discusses I-JSON | ||||
conformance in more detail. | ||||
2. Terminology and Notation | 2. Terminology and Notation | |||
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", | The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", | |||
"SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this | "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this | |||
document are to be interpreted as described in [RFC2119]. | document are to be interpreted as described in [RFC2119]. | |||
The following terms are defined in [I-D.ietf-netmod-rfc6020bis]: | The following terms are defined in [I-D.ietf-netmod-rfc6020bis]: | |||
o action, | ||||
o anydata, | o anydata, | |||
o anyxml, | o anyxml, | |||
o augment, | o augment, | |||
o container, | o container, | |||
o data node, | o data node, | |||
o data tree, | ||||
o identity, | o identity, | |||
o instance identifier, | o instance identifier, | |||
o leaf, | o leaf, | |||
o leaf-list, | o leaf-list, | |||
o list, | o list, | |||
o module, | o module, | |||
o RPC operation, | ||||
o submodule. | o submodule. | |||
3. Validation of JSON-encoded Instance Data | 3. Properties of the JSON Encoding | |||
Instance data validation as defined in [I-D.ietf-netmod-rfc6020bis], | This document defines JSON encoding for YANG data trees and their | |||
sec. 8.3.3, is only applicable to XML-encoded data. For one, | subtrees. It is always assumed that the top-level structure in JSON- | |||
semantic constraints in "must" statements are expressed using | encoded data is an object. | |||
XPath 1.0 [W3C.REC-xpath-19991116], which can be properly interpreted | ||||
only in the XML context. | ||||
This document and the corresponding "XML Mapping Rules" sections from | Instances of YANG data nodes (leafs, containers, leaf-lists, lists, | |||
[I-D.ietf-netmod-rfc6020bis] also define an implicit schema-driven | anydata and anyxml nodes) are encoded as members of a JSON object, | |||
mapping of JSON-encoded instances to XML-encoded instances (and vice | i.e., name/value pairs. Section 4 defines how the name part is | |||
versa). This mapping is mostly straightforward. In cases where | formed, and the following sections deal with the value part. | |||
doubts could arise, this document gives explicit instructions for | ||||
mapping JSON-encoded instances to XML. | ||||
In order to validate a JSON instance document, it needs first to be | Unlike XML element content, JSON values carry partial type | |||
mapped, at least conceptually, to the corresponding XML instance | information (number, string, boolean). The JSON encoding is defined | |||
document. By definition, the JSON document is then valid if and only | so that this information is never in conflict with the data type of | |||
if the XML document is valid according to the rules stated in | the corresponding YANG leaf or leaf-list. | |||
[I-D.ietf-netmod-rfc6020bis]. | ||||
With the exception of anyxml and schema-less anydata nodes, it is | ||||
possible to map a JSON-encoded data tree to XML encoding as defined | ||||
in [I-D.ietf-netmod-rfc6020bis], and vice versa. However, such | ||||
conversions require the YANG data model to be available. | ||||
In order to achieve maximum interoperability while allowing | ||||
implementations to use a variety of existing JSON parsers, the JSON | ||||
encoding rules follow, as much as possible, the constraints of the | ||||
I-JSON restricted profile [RFC7493]. Section 7 discusses I-JSON | ||||
conformance in more detail. | ||||
4. Names and Namespaces | 4. Names and Namespaces | |||
Instances of YANG data nodes (leafs, containers, leaf-lists, lists, | An object member name MUST be in one of the following forms: | |||
anydata and anyxml nodes) are always encoded as members of a JSON | ||||
object, i.e., as name/value pairs. This section defines how the name | ||||
part is formed, and the following sections deal with the value part. | ||||
Except in the cases specified below, the member name is identical to | o simple - identical to the identifier of the corresponding YANG | |||
the identifier of the corresponding YANG data node. Every such name | data node; | |||
belongs to a namespace which is associated with the YANG module where | ||||
the corresponding data node is defined. If the data node is defined | ||||
in a submodule, then the namespace is determined by the main module | ||||
to which the submodule belongs. | ||||
If the namespace of a member name has to be explicitly specified, the | o namespace-qualified - the data node identifier is prefixed with | |||
module name SHALL be used as a prefix to the member's local name. | the name of the module in which the data node is defined, and | |||
Both parts of the member name SHALL be separated with a colon | separated by the colon character (":"). | |||
character (":"). Using ABNF [RFC5234], the namespace-qualified name | ||||
can be expressed as shown in Figure 1, where the production for | ||||
"identifier" is defined in sec. 13 of [I-D.ietf-netmod-rfc6020bis]. | ||||
qualified-member-name = identifier ":" identifier | The name of a module determines the namespace of all data node names | |||
defined in that module. If a data node is defined in a submodule, | ||||
then the namespace-qualified member name uses the name of the main | ||||
module to which the submodule belongs. | ||||
Figure 1: ABNF production for a qualified member name. | ABNF syntax [RFC5234] of a member name is shown in Figure 1, where | |||
the production for "identifier" is defined in sec. 13 of | ||||
[I-D.ietf-netmod-rfc6020bis]. | ||||
Names with namespace identifiers in the form shown in Figure 1 are | member-name = [identifier ":"] identifier | |||
used if and only if the parent data node belongs to a different | ||||
namespace, which also includes all top-level YANG data nodes that | Figure 1: ABNF production for a JSON member name. | |||
have no parent node. | ||||
A namespace-qualified member name MUST be used for all members of a | ||||
top-level JSON object, and then also whenever the namespaces of the | ||||
data node and its parent node are different. In all other cases, the | ||||
simple form of the member name MUST be used. | ||||
For example, consider the following YANG module: | For example, consider the following YANG module: | |||
module foomod { | module foomod { | |||
namespace "http://example.com/foomod"; | namespace "http://example.com/foomod"; | |||
prefix "foo"; | prefix "foo"; | |||
container top { | container top { | |||
skipping to change at page 5, line 31 | skipping to change at page 5, line 38 | |||
If the data model consists only of this module, then the following is | If the data model consists only of this module, then the following is | |||
a valid JSON-encoded configuration: | a valid JSON-encoded configuration: | |||
{ | { | |||
"foomod:top": { | "foomod:top": { | |||
"foo": 54 | "foo": 54 | |||
} | } | |||
} | } | |||
Note that the top-level container instance contains the namespace | Note that the member of the top-level object uses the namespace- | |||
identifier (module name) but the "foo" leaf doesn't because it is | qualified name but the "foo" leaf doesn't because it is defined in | |||
defined in the same module as its parent container. | the same module as its parent container "top". | |||
Now, assume the container "top" is augmented from another module, | Now, assume the container "top" is augmented from another module, | |||
"barmod": | "barmod": | |||
module barmod { | module barmod { | |||
namespace "http://example.com/barmod"; | namespace "http://example.com/barmod"; | |||
prefix "bar"; | prefix "bar"; | |||
skipping to change at page 6, line 33 | skipping to change at page 6, line 33 | |||
look like this: | look like this: | |||
{ | { | |||
"foomod:top": { | "foomod:top": { | |||
"foo": 54, | "foo": 54, | |||
"barmod:bar": true | "barmod:bar": true | |||
} | } | |||
} | } | |||
The name of the "bar" leaf is prefixed with the namespace identifier | The name of the "bar" leaf is prefixed with the namespace identifier | |||
because its parent is defined in a different module, hence it belongs | because its parent is defined in a different module. | |||
to another namespace. | ||||
Explicit namespace identifiers are sometimes needed when encoding | Explicit namespace identifiers are sometimes needed when encoding | |||
values of the "identityref" and "instances-identifier" types. The | values of the "identityref" and "instances-identifier" types. The | |||
same form as shown in Figure 1 is then used as well. See Sections | same form of namespace-qualified name as defined above is then used. | |||
6.8 and 6.11 for details. | See Sections 6.8 and 6.11 for details. | |||
5. Encoding of YANG Data Node Instances | 5. Encoding of YANG Data Node Instances | |||
Every complete JSON instance document, such as a configuration | Every data node instance is encoded as a name/value pair where the | |||
datastore content, is an object. Its members are instances of all | name is formed from the data node identifier using the rules of | |||
top-level data nodes defined by the YANG data model. | Section 4. The value depends on the category of the data node as | |||
explained in the following subsections. | ||||
Character encoding MUST be UTF-8. | Character encoding MUST be UTF-8. | |||
Any data node instance is encoded as a name/value pair where the name | ||||
is formed from the data node identifier using the rules of Section 4. | ||||
The value depends on the category of the data node as explained in | ||||
the following subsections. | ||||
5.1. The "leaf" Data Node | 5.1. The "leaf" Data Node | |||
A leaf instance is encoded as a name/value pair where the value can | A leaf instance is encoded as a name/value pair where the value can | |||
be a string, number, literal "true" or "false", or the special array | be a string, number, literal "true" or "false", or the special array | |||
"[null]", depending on the type of the leaf (see Section 6 for the | "[null]", depending on the type of the leaf (see Section 6 for the | |||
type encoding rules). | type encoding rules). | |||
Example: For the leaf node definition | Example: For the leaf node definition | |||
leaf foo { | leaf foo { | |||
skipping to change at page 9, line 19 | skipping to change at page 9, line 19 | |||
}, | }, | |||
{ | { | |||
"baz": "zag", | "baz": "zag", | |||
"foo": 0 | "foo": 0 | |||
} | } | |||
] | ] | |||
5.5. The "anydata" Data Node | 5.5. The "anydata" Data Node | |||
Anydata data node is a new feature in YANG 1.1. It serves as a | Anydata data node is a new feature in YANG 1.1. It serves as a | |||
container for data that appear as normal YANG-modeled data, except | container for an unknown set of nodes that however appear as normal | |||
their data model is not a priori known. | YANG-modeled data. A data model for anydata content may or may not | |||
exist at run time. In the latter case, no universal mapping between | ||||
JSON- and XML-encoded instances is available. | ||||
An anydata instance is thus encoded in the same way as a container, | An anydata instance is encoded in the same way as a container, i.e., | |||
and its content is subject to the following rules: | as a value/object pair. The requirement that anydata content can be | |||
modeled by YANG implies the following rules for JSON text inside the | ||||
object: | ||||
o It is a valid I-JSON message [RFC7493]. | o It is valid I-JSON [RFC7493]. | |||
o Any member name is either a YANG identifier as defined by the | o All object member names satisfy the ABNF production in Figure 1. | |||
"identifier" production in sec. 13 of | ||||
[I-D.ietf-netmod-rfc6020bis], or two such identifiers separated by | ||||
the colon character (":"). See also Section 4. | ||||
o Any JSON array contains either only unique scalar values (as a | o Any JSON array contains either only unique scalar values (as a | |||
leaf-list, see Section 5.3), or only objects (as a list, see | leaf-list, see Section 5.3), or only objects (as a list, see | |||
Section 5.4). | Section 5.4). | |||
o The "null" value is only allowed in the single-element array | o The "null" value is only allowed in the single-element array | |||
"[null]" corresponding to the encoding of the "empty" type, see | "[null]" corresponding to the encoding of the "empty" type, see | |||
Section 6.9. | Section 6.9. | |||
If a data model for anydata content is not available, it may be | ||||
impossible to map a JSON-encoded anydata instance to XML, and vice | ||||
versa. Note, however, that such a mapping is not needed for | ||||
validation purposes (Section 3) because anydata contents are | ||||
generally not subject to YANG-based validation (see sec. 7.10 in | ||||
[I-D.ietf-netmod-rfc6020bis]). | ||||
Example: for the anydata definition | Example: for the anydata definition | |||
anydata data; | anydata data; | |||
the following is a valid JSON-encoded instance: | the following is a valid JSON-encoded instance: | |||
"data": { | "data": { | |||
"ietf-notification:notification": { | "ietf-notification:notification": { | |||
"eventTime": "2014-07-29T13:43:01Z", | "eventTime": "2014-07-29T13:43:01Z", | |||
"example-event:event": { | "example-event:event": { | |||
skipping to change at page 10, line 25 | skipping to change at page 10, line 25 | |||
} | } | |||
} | } | |||
5.6. The "anyxml" Data Node | 5.6. The "anyxml" Data Node | |||
An anyxml instance is encoded as a JSON name/value pair which MUST | An anyxml instance is encoded as a JSON name/value pair which MUST | |||
satisfy I-JSON constraints. Otherwise it is unrestricted, i.e., the | satisfy I-JSON constraints. Otherwise it is unrestricted, i.e., the | |||
value can be an object, array, number, string or one of the literals | value can be an object, array, number, string or one of the literals | |||
"true", "false" and "null". | "true", "false" and "null". | |||
As in the case of anydata (Section 5.5), there is no universal | There is no universal procedure for mapping JSON-encoded anyxml | |||
procedure for mapping JSON-encoded anyxml instances to XML, and vice | instances to XML, and vice versa. | |||
versa. | ||||
Example: For the anyxml definition | Example: For the anyxml definition | |||
anyxml bar; | anyxml bar; | |||
the following is a valid JSON-encoded instance: | the following is a valid JSON-encoded instance: | |||
"bar": [true, null, true] | "bar": [true, null, true] | |||
6. The Mapping of YANG Data Types to JSON Values | 6. Representing YANG Data Types in JSON Values | |||
The type of the JSON value in an instance of the leaf or leaf-list | The type of the JSON value in an instance of the leaf or leaf-list | |||
data node depends on the type of that data node as specified in the | data node depends on the type of that data node as specified in the | |||
following subsections. | following subsections. | |||
6.1. Numeric Types | 6.1. Numeric Types | |||
A value of the "int8", "int16", "int32", "uint8", "uint16" and | A value of the types "int8", "int16", "int32", "uint8", "uint16" and | |||
"uint32" is represented as a JSON number. | "uint32" is represented as a JSON number. | |||
A value of the "int64", "uint64" or "decimal64" type is encoded as a | A value of the "int64", "uint64" or "decimal64" type is represented | |||
JSON string whose contents is the lexical representation of that | as a JSON string whose content is the lexical representation of the | |||
numeric value as specified in sections 9.2.1 and 9.3.1 of | corresponding YANG type as specified in sections 9.2.1 and 9.3.1 of | |||
[I-D.ietf-netmod-rfc6020bis]. | [I-D.ietf-netmod-rfc6020bis]. | |||
For example, if the type of the leaf "foo" in Section 5.1 was | For example, if the type of the leaf "foo" in Section 5.1 was | |||
"uint64" instead of "uint8", the instance would have to be encoded as | "uint64" instead of "uint8", the instance would have to be encoded as | |||
"foo": "123" | "foo": "123" | |||
The special handling of 64-bit numbers follows from I-JSON | The special handling of 64-bit numbers follows from the I-JSON | |||
recommendation to encode numbers exceeding the IEEE 754-2008 double | recommendation to encode numbers exceeding the IEEE 754-2008 double | |||
precision range as strings, see sec. 2.2 in [RFC7493]. | precision range as strings, see sec. 2.2 in [RFC7493]. | |||
6.2. The "string" Type | 6.2. The "string" Type | |||
A "string" value encoded as a JSON string, subject to JSON string | A "string" value represented as a JSON string, subject to JSON string | |||
encoding rules. | encoding rules. | |||
6.3. The "boolean" Type | 6.3. The "boolean" Type | |||
A "boolean" value is mapped to the corresponding JSON literal name | A "boolean" value is represented as the corresponding JSON literal | |||
"true" or "false". | name "true" or "false". | |||
6.4. The "enumeration" Type | 6.4. The "enumeration" Type | |||
An "enumeration" value is mapped in the same way as a string except | An "enumeration" value is represented as a JSON string - one of the | |||
that the permitted values are defined by "enum" statements in YANG. | names assigned by "enum" statements in YANG. | |||
See sec. 9.6 in [I-D.ietf-netmod-rfc6020bis]. | ||||
The representation is identical to the lexical representation of the | ||||
"enumeration" type in XML, see sec. 9.6 in | ||||
[I-D.ietf-netmod-rfc6020bis]. | ||||
6.5. The "bits" Type | 6.5. The "bits" Type | |||
A "bits" value is mapped to a JSON string identical to the lexical | A "bits" value is represented as a JSON string - a space-separated | |||
representation of this value in XML, i.e., space-separated names | sequence of names of bits that are set. The permitted bit names are | |||
representing the individual bit values that are set. See sec. 9.7 in | assigned by "bit" statements in YANG. | |||
[I-D.ietf-netmod-rfc6020bis]. | ||||
The representation is identical to the lexical representation of the | ||||
"bits" type, see sec. 9.7 in [I-D.ietf-netmod-rfc6020bis]. | ||||
6.6. The "binary" Type | 6.6. The "binary" Type | |||
A "binary" value is mapped to a JSON string identical to the lexical | A "binary" value is represented as a JSON string - base64-encoding of | |||
representation of this value in XML, i.e., base64-encoded binary | arbitrary binary data. | |||
data. See sec. 9.8 in [I-D.ietf-netmod-rfc6020bis]. | ||||
The representation is identical to the lexical representation of the | ||||
"binary" type in XML, see sec. 9.8 in [I-D.ietf-netmod-rfc6020bis]. | ||||
6.7. The "leafref" Type | 6.7. The "leafref" Type | |||
A "leafref" value is mapped according to the same rules as the type | A "leafref" value is represented using the same rules as the type of | |||
of the leaf being referred to. | the leaf to which the leafref value refers. | |||
6.8. The "identityref" Type | 6.8. The "identityref" Type | |||
An "identityref" value is mapped to a string representing the name of | An "identityref" value is represented as a string - the name of an | |||
an identity. Its namespace MUST be expressed as shown in Figure 1 if | identity. If the identity is defined in another module than the leaf | |||
it is different from the namespace of the leaf node containing the | node containing the identityref value, the namespace-qualified form | |||
identityref value, and MAY be expressed otherwise. | (Section 4) MUST be used. Otherwise, both the simple and namespace- | |||
qualified forms are permitted. | ||||
For example, consider the following schematic module: | For example, consider the following schematic module: | |||
module exmod { | module exmod { | |||
... | ... | |||
import ietf-interfaces { | import ietf-interfaces { | |||
prefix if; | prefix if; | |||
} | } | |||
import iana-if-type { | import iana-if-type { | |||
prefix ianaift; | prefix ianaift; | |||
skipping to change at page 12, line 35 | skipping to change at page 12, line 46 | |||
A valid instance of the "type" leaf is then encoded as follows: | A valid instance of the "type" leaf is then encoded as follows: | |||
"type": "iana-if-type:ethernetCsmacd" | "type": "iana-if-type:ethernetCsmacd" | |||
The namespace identifier "iana-if-type" must be present in this case | The namespace identifier "iana-if-type" must be present in this case | |||
because the "ethernetCsmacd" identity is not defined in the same | because the "ethernetCsmacd" identity is not defined in the same | |||
module as the "type" leaf. | module as the "type" leaf. | |||
6.9. The "empty" Type | 6.9. The "empty" Type | |||
An "empty" value is mapped to "[null]", i.e., an array with the | An "empty" value is represented as "[null]", i.e., an array with the | |||
"null" literal being its only element. For the purposes of this | "null" literal being its only element. For the purposes of this | |||
document, "[null]" is treated as an atomic scalar value. | document, "[null]" is considered an atomic scalar value. | |||
This encoding of the "empty" type was chosen instead of using simply | This encoding of the "empty" type was chosen instead of using simply | |||
"null" in order to facilitate the use of empty leafs in common | "null" in order to facilitate the use of empty leafs in common | |||
programming languages. When used in a boolean context, the "[null]" | programming languages where the "null" value of a member is treated | |||
value, unlike "null", evaluates to true. | as if the member is not present. | |||
Example: For the leaf definition | Example: For the leaf definition | |||
leaf foo { | leaf foo { | |||
type empty; | type empty; | |||
} | } | |||
a valid instance is | a valid instance is | |||
"foo": [null] | "foo": [null] | |||
6.10. The "union" Type | 6.10. The "union" Type | |||
A value of the "union" type is encoded as the value of any of the | A value of the "union" type is encoded as the value of any of the | |||
member types. | member types. | |||
Unlike XML, JSON conveys part of the type information already in the | When validating a value of the "union" type, the type information | |||
encoding. When validating a value of the "union" type, this | conveyed by the JSON encoding MUST also be taken into account. | |||
information MUST also be taken into account. | ||||
For example, consider the following YANG definition: | For example, consider the following YANG definition: | |||
leaf bar { | leaf bar { | |||
type union { | type union { | |||
type uint16; | type uint16; | |||
type string; | type string; | |||
} | } | |||
} | } | |||
In RESTCONF [I-D.ietf-netconf-restconf], it is fully acceptable to | In RESTCONF [I-D.ietf-netconf-restconf], it is possible to set the | |||
set the value of "bar" in the following way when using the | value of "bar" in the following way when using the "application/ | |||
"application/yang.data+xml" media type: | yang.data+xml" media type: | |||
<bar>13.5</bar> | <bar>13.5</bar> | |||
because the value may be interpreted as a string, i.e., the second | because the value may be interpreted as a string, i.e., the second | |||
member type of the union. When using the "application/ | member type of the union. When using the "application/ | |||
yang.data+json" media type, however, this is an error: | yang.data+json" media type, however, this is an error: | |||
"bar": 13.5 | "bar": 13.5 | |||
In this case, the JSON encoding indicates the value is supposed to be | In this case, the JSON encoding indicates the value is supposed to be | |||
a number rather than a string. | a number rather than a string. | |||
6.11. The "instance-identifier" Type | 6.11. The "instance-identifier" Type | |||
An "instance-identifier" value is encoded as a string that is | An "instance-identifier" value is encoded as a string that is | |||
analogical to the lexical representation in XML encoding, see | analogical to the lexical representation in XML encoding, see | |||
sec. 9.13.3 in [I-D.ietf-netmod-rfc6020bis]. However, the encoding | sec. 9.13.3 in [I-D.ietf-netmod-rfc6020bis]. However, the encoding | |||
of namespaces in instance-identifier values follows the rules stated | of namespaces in instance-identifier values follows the rules stated | |||
in Section 4, namely: | in Section 4, namely: | |||
o The namespace identifier is the module name where each data node | o The leftmost (top-level) data node name is always in the | |||
is defined. | namespace-qualified form. | |||
o The encoding of a node name with an explicit namespace is as shown | ||||
in Figure 1. | ||||
o The leftmost (top-level) node name is always prefixed with the | ||||
namespace identifier. | ||||
o Any subsequent node name has the namespace identifier if and only | o Any subsequent data node name is in the namespace-qualified form | |||
if its parent node has a different namespace. This also holds for | if the node is defined in another module than its parent node, and | |||
node names appearing in predicates. | the simple form is used otherwise. This rule also holds for node | |||
names appearing in predicates. | ||||
For example, | For example, | |||
/ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/ip | /ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/ip | |||
is a valid instance-identifer value because the data nodes | is a valid instance-identifer value because the data nodes | |||
"interfaces", "interface" and "name" are defined in the module "ietf- | "interfaces", "interface" and "name" are defined in the module "ietf- | |||
interfaces", whereas "ipv4" and "ip" are defined in "ietf-ip". | interfaces", whereas "ipv4" and "ip" are defined in "ietf-ip". | |||
When translating an instance-identifier value from JSON to XML, the | ||||
namespace identifier (YANG module name) in each component of the | ||||
instance-identifier MUST be replaced by an XML namespace prefix that | ||||
is associated with the namespace URI reference of the module in the | ||||
scope of the element containing the instance-identifier value. | ||||
7. I-JSON Compliance | 7. I-JSON Compliance | |||
I-JSON [RFC7493] is a restricted profile of JSON that guarantees | I-JSON [RFC7493] is a restricted profile of JSON that guarantees | |||
maximum interoperability for protocols that use JSON in their | maximum interoperability for protocols that use JSON in their | |||
messages, no matter what JSON encoders/decoders are used in protocol | messages, no matter what JSON encoders/decoders are used in protocol | |||
implementations. The encoding defined in this document therefore | implementations. The encoding defined in this document therefore | |||
observes the I-JSON requirements and recommendations as closely as | observes the I-JSON requirements and recommendations as closely as | |||
possible. | possible. | |||
In particular, the following properties are guaranteed: | In particular, the following properties are guaranteed: | |||
o Character encoding is UTF-8. | o Character encoding is UTF-8. | |||
o Member names within the same JSON object are always unique. | o Member names within the same JSON object are always unique. | |||
o The order of JSON object members is never relied upon. | o The order of JSON object members is never relied upon. | |||
o Numbers of any type supported by YANG can be exchanged reliably. | o Numbers of any type supported by YANG can be exchanged reliably. | |||
See Section 6.1 for details. | See Section 6.1 for details. | |||
This document deviates from I-JSON only in the encoding of values | The JSON encoding defined in this document deviates from I-JSON only | |||
with the "binary" type. It uses the base64 encoding scheme | in the representation of the "binary" type. In order to remain | |||
compatible with XML encoding, the base64 encoding scheme is used | ||||
(Section 6.6), whereas I-JSON recommends base64url instead. | (Section 6.6), whereas I-JSON recommends base64url instead. | |||
Theoretically, values of the "binary" type might appear in URI | ||||
references, such as Request-URI in RESTCONF, although in practice the | ||||
cases where it is really needed should be extremely rare. | ||||
8. Security Considerations | 8. Security Considerations | |||
This document defines an alternative encoding for data modeled in the | This document defines an alternative encoding for data modeled in the | |||
YANG data modeling language. As such, it doesn't contribute any new | YANG data modeling language. As such, it doesn't contribute any new | |||
security issues beyond those discussed in sec. 16 of | security issues beyond those discussed in sec. 16 of | |||
[I-D.ietf-netmod-rfc6020bis]. | [I-D.ietf-netmod-rfc6020bis]. | |||
JSON processing is rather different from XML, and JSON parsers may | JSON processing is rather different from XML, and JSON parsers may | |||
thus suffer from other types of vulnerabilities than their XML | thus suffer from other types of vulnerabilities than their XML | |||
skipping to change at page 15, line 32 | skipping to change at page 15, line 32 | |||
Bogdanovic, Balazs Lengyel, Juergen Schoenwaelder and Phil Shafer for | Bogdanovic, Balazs Lengyel, Juergen Schoenwaelder and Phil Shafer for | |||
their helpful comments and suggestions. | their helpful comments and suggestions. | |||
10. References | 10. References | |||
10.1. Normative References | 10.1. Normative References | |||
[I-D.ietf-netmod-rfc6020bis] | [I-D.ietf-netmod-rfc6020bis] | |||
Bjorklund, M., "YANG - A Data Modeling Language for the | Bjorklund, M., "YANG - A Data Modeling Language for the | |||
Network Configuration Protocol (NETCONF)", draft-ietf- | Network Configuration Protocol (NETCONF)", draft-ietf- | |||
netmod-rfc6020bis-05 (work in progress), May 2015. | netmod-rfc6020bis-06 (work in progress), July 2015. | |||
[RFC2119] Bradner, S., "Key words for use in RFCs to Indicate | [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate | |||
Requirement Levels", BCP 14, RFC 2119, March 1997. | Requirement Levels", BCP 14, RFC 2119, DOI 10.17487/ | |||
RFC2119, March 1997, | ||||
[RFC5234] Crocker, D. and P. Overell, "Augmented BNF for Syntax | <http://www.rfc-editor.org/info/rfc2119>. | |||
Specifications: ABNF", STD 68, RFC 5234, January 2008. | ||||
[RFC6241] Enns, R., Bjorklund, M., Schoenwaelder, J., and A. | [RFC5234] Crocker, D., Ed. and P. Overell, "Augmented BNF for Syntax | |||
Bierman, "Network Configuration Protocol (NETCONF)", RFC | Specifications: ABNF", STD 68, RFC 5234, DOI 10.17487/ | |||
6241, June 2011. | RFC5234, January 2008, | |||
<http://www.rfc-editor.org/info/rfc5234>. | ||||
[RFC7159] Bray, T., "The JavaScript Object Notation (JSON) Data | [RFC6241] Enns, R., Ed., Bjorklund, M., Ed., Schoenwaelder, J., Ed., | |||
Interchange Format", RFC 7159, March 2014. | and A. Bierman, Ed., "Network Configuration Protocol | |||
(NETCONF)", RFC 6241, DOI 10.17487/RFC6241, June 2011, | ||||
<http://www.rfc-editor.org/info/rfc6241>. | ||||
[RFC7493] Bray, T., "The I-JSON Message Format", RFC 7493, March | [RFC7159] Bray, T., Ed., "The JavaScript Object Notation (JSON) Data | |||
2015. | Interchange Format", RFC 7159, DOI 10.17487/RFC7159, March | |||
2014, <http://www.rfc-editor.org/info/rfc7159>. | ||||
[W3C.REC-xml-20081126] | [RFC7493] Bray, T., Ed., "The I-JSON Message Format", RFC 7493, DOI | |||
Bray, T., Paoli, J., Sperberg-McQueen, M., Maler, E., and | 10.17487/RFC7493, March 2015, | |||
F. Yergeau, "Extensible Markup Language (XML) 1.0 (Fifth | <http://www.rfc-editor.org/info/rfc7493>. | |||
Edition)", World Wide Web Consortium Recommendation REC- | ||||
xml-20081126, November 2008, | ||||
<http://www.w3.org/TR/2008/REC-xml-20081126>. | ||||
10.2. Informative References | 10.2. Informative References | |||
[I-D.ietf-netconf-restconf] | [I-D.ietf-netconf-restconf] | |||
Bierman, A., Bjorklund, M., and K. Watsen, "RESTCONF | Bierman, A., Bjorklund, M., and K. Watsen, "RESTCONF | |||
Protocol", draft-ietf-netconf-restconf-05 (work in | Protocol", draft-ietf-netconf-restconf-07 (work in | |||
progress), June 2015. | progress), July 2015. | |||
[RFC7223] Bjorklund, M., "A YANG Data Model for Interface | [RFC7223] Bjorklund, M., "A YANG Data Model for Interface | |||
Management", RFC 7223, May 2014. | Management", RFC 7223, DOI 10.17487/RFC7223, May 2014, | |||
<http://www.rfc-editor.org/info/rfc7223>. | ||||
[W3C.REC-xpath-19991116] | [W3C.REC-xml-20081126] | |||
Clark, J. and S. DeRose, "XML Path Language (XPath) | Bray, T., Paoli, J., Sperberg-McQueen, M., Maler, E., and | |||
Version 1.0", World Wide Web Consortium Recommendation | F. Yergeau, "Extensible Markup Language (XML) 1.0 (Fifth | |||
REC-xpath-19991116, November 1999, | Edition)", World Wide Web Consortium Recommendation REC- | |||
<http://www.w3.org/TR/1999/REC-xpath-19991116>. | xml-20081126, November 2008, | |||
<http://www.w3.org/TR/2008/REC-xml-20081126>. | ||||
Appendix A. A Complete Example | Appendix A. A Complete Example | |||
The JSON document shown below represents the same data as the reply | The JSON document shown below represents the same data as the reply | |||
to the NETCONF <get> request appearing in Appendix D of [RFC7223]. | to the NETCONF <get> request appearing in Appendix D of [RFC7223]. | |||
The data model is a combination of two YANG modules: "ietf- | The data model is a combination of two YANG modules: "ietf- | |||
interfaces" and "ex-vlan" (the latter is an example module from | interfaces" and "ex-vlan" (the latter is an example module from | |||
Appendix C of [RFC7223]). The "if-mib" feature defined in the "ietf- | Appendix C of [RFC7223]). The "if-mib" feature defined in the "ietf- | |||
interfaces" module is considered to be active. | interfaces" module is considered to be active. | |||
skipping to change at page 18, line 37 | skipping to change at page 18, line 36 | |||
} | } | |||
} | } | |||
] | ] | |||
} | } | |||
} | } | |||
Appendix B. Change Log | Appendix B. Change Log | |||
RFC Editor: Remove this section upon publication as an RFC. | RFC Editor: Remove this section upon publication as an RFC. | |||
B.1. Changes Between Revisions -03 and -04 | B.1. Changes Between Revisions -04 and -05 | |||
o Removed section "Validation of JSON-encoded Instance Data" and | ||||
other text about XML-JSON mapping. | ||||
o Added section "Properties of the JSON Encoding". | ||||
B.2. Changes Between Revisions -03 and -04 | ||||
o I-D.ietf-netmod-rfc6020bis is used as a normative reference | o I-D.ietf-netmod-rfc6020bis is used as a normative reference | |||
instead of RFC 6020. | instead of RFC 6020. | |||
o Removed noncharacters as an I-JSON issue because it doesn't exist | o Removed noncharacters as an I-JSON issue because it doesn't exist | |||
in YANG 1.1. | in YANG 1.1. | |||
o Section about anydata encoding was added. | o Section about anydata encoding was added. | |||
o Require I-JSON for anyxml encoding. | o Require I-JSON for anyxml encoding. | |||
o Use ABNF for defining qualified name. | o Use ABNF for defining qualified name. | |||
B.2. Changes Between Revisions -02 and -03 | B.3. Changes Between Revisions -02 and -03 | |||
o Namespace encoding is defined without using RFC 2119 keywords. | o Namespace encoding is defined without using RFC 2119 keywords. | |||
o Specification for anyxml nodes was extended and clarified. | o Specification for anyxml nodes was extended and clarified. | |||
o Text about ordering of list entries was corrected. | o Text about ordering of list entries was corrected. | |||
B.3. Changes Between Revisions -01 and -02 | B.4. Changes Between Revisions -01 and -02 | |||
o Encoding of namespaces in instance-identifiers was changed. | o Encoding of namespaces in instance-identifiers was changed. | |||
o Text specifying the order of array elements in leaf-list and list | o Text specifying the order of array elements in leaf-list and list | |||
instances was added. | instances was added. | |||
B.4. Changes Between Revisions -00 and -01 | B.5. Changes Between Revisions -00 and -01 | |||
o Metadata encoding was moved to a separate I-D, draft-lhotka- | o Metadata encoding was moved to a separate I-D, draft-lhotka- | |||
netmod-yang-metadata. | netmod-yang-metadata. | |||
o JSON encoding is now defined directly rather than via XML-JSON | o JSON encoding is now defined directly rather than via XML-JSON | |||
mapping. | mapping. | |||
o The rules for namespace encoding has changed. This affect both | o The rules for namespace encoding has changed. This affect both | |||
node instance names and instance-identifiers. | node instance names and instance-identifiers. | |||
End of changes. 69 change blocks. | ||||
186 lines changed or deleted | 184 lines changed or added | |||
This html diff was produced by rfcdiff 1.42. The latest version is available from http://tools.ietf.org/tools/rfcdiff/ |