draft-ietf-netmod-yang-json-10.txt   rfc7951.txt 
NETMOD Working Group L. Lhotka Internet Engineering Task Force (IETF) L. Lhotka
Internet-Draft CZ.NIC Request for Comments: 7951 CZ.NIC
Intended status: Standards Track March 26, 2016 Category: Standards Track August 2016
Expires: September 27, 2016 ISSN: 2070-1721
JSON Encoding of Data Modeled with YANG JSON Encoding of Data Modeled with YANG
draft-ietf-netmod-yang-json-10
Abstract Abstract
This document defines encoding rules for representing configuration This document defines encoding rules for representing configuration
data, state data, parameters of RPC operations or actions, and data, state data, parameters of Remote Procedure Call (RPC)
notifications defined using YANG as JavaScript Object Notation (JSON) operations or actions, and notifications defined using YANG as
text. JavaScript Object Notation (JSON) text.
Status of This Memo Status of This Memo
This Internet-Draft is submitted in full conformance with the This is an Internet Standards Track document.
provisions of BCP 78 and BCP 79.
Internet-Drafts are working documents of the Internet Engineering
Task Force (IETF). Note that other groups may also distribute
working documents as Internet-Drafts. The list of current Internet-
Drafts is at http://datatracker.ietf.org/drafts/current/.
Internet-Drafts are draft documents valid for a maximum of six months This document is a product of the Internet Engineering Task Force
and may be updated, replaced, or obsoleted by other documents at any (IETF). It represents the consensus of the IETF community. It has
time. It is inappropriate to use Internet-Drafts as reference received public review and has been approved for publication by the
material or to cite them other than as "work in progress." Internet Engineering Steering Group (IESG). Further information on
Internet Standards is available in Section 2 of RFC 7841.
This Internet-Draft will expire on September 27, 2016. Information about the current status of this document, any errata,
and how to provide feedback on it may be obtained at
http://www.rfc-editor.org/info/rfc7951.
Copyright Notice Copyright Notice
Copyright (c) 2016 IETF Trust and the persons identified as the Copyright (c) 2016 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
skipping to change at page 2, line 13 skipping to change at page 2, line 13
described in the Simplified BSD License. described in the Simplified BSD License.
Table of Contents Table of Contents
1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . 3 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . 3
2. Terminology and Notation . . . . . . . . . . . . . . . . . . 3 2. Terminology and Notation . . . . . . . . . . . . . . . . . . 3
3. Properties of the JSON Encoding . . . . . . . . . . . . . . . 4 3. Properties of the JSON Encoding . . . . . . . . . . . . . . . 4
4. Names and Namespaces . . . . . . . . . . . . . . . . . . . . 5 4. Names and Namespaces . . . . . . . . . . . . . . . . . . . . 5
5. Encoding of YANG Data Node Instances . . . . . . . . . . . . 7 5. Encoding of YANG Data Node Instances . . . . . . . . . . . . 7
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 . . . . . . . . . . . . . . . . 8
5.3. The "leaf-list" Data Node . . . . . . . . . . . . . . . . 8 5.3. The "leaf-list" Data Node . . . . . . . . . . . . . . . . 8
5.4. The "list" Data Node . . . . . . . . . . . . . . . . . . 8 5.4. The "list" Data Node . . . . . . . . . . . . . . . . . . 9
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
5.7. Metadata Objects . . . . . . . . . . . . . . . . . . . . 10 5.7. Metadata Objects . . . . . . . . . . . . . . . . . . . . 11
6. Representing YANG Data Types in JSON Values . . . . . . . . . 10 6. Representing YANG Data Types in JSON Values . . . . . . . . . 11
6.1. Numeric Types . . . . . . . . . . . . . . . . . . . . . . 11 6.1. Numeric Types . . . . . . . . . . . . . . . . . . . . . . 11
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 . . . . . . . . . . . . . . . . . 12
6.5. The "bits" Type . . . . . . . . . . . . . . . . . . . . . 11 6.5. The "bits" Type . . . . . . . . . . . . . . . . . . . . . 12
6.6. The "binary" Type . . . . . . . . . . . . . . . . . . . . 12 6.6. The "binary" Type . . . . . . . . . . . . . . . . . . . . 12
6.7. The "leafref" Type . . . . . . . . . . . . . . . . . . . 12 6.7. The "leafref" Type . . . . . . . . . . . . . . . . . . . 12
6.8. The "identityref" Type . . . . . . . . . . . . . . . . . 12 6.8. The "identityref" Type . . . . . . . . . . . . . . . . . 12
6.9. The "empty" Type . . . . . . . . . . . . . . . . . . . . 13 6.9. The "empty" Type . . . . . . . . . . . . . . . . . . . . 13
6.10. The "union" Type . . . . . . . . . . . . . . . . . . . . 13 6.10. The "union" Type . . . . . . . . . . . . . . . . . . . . 14
6.11. The "instance-identifier" Type . . . . . . . . . . . . . 14 6.11. The "instance-identifier" Type . . . . . . . . . . . . . 15
7. I-JSON Compliance . . . . . . . . . . . . . . . . . . . . . . 14 7. I-JSON Compliance . . . . . . . . . . . . . . . . . . . . . . 15
8. Security Considerations . . . . . . . . . . . . . . . . . . . 15 8. Security Considerations . . . . . . . . . . . . . . . . . . . 16
9. Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . 15 9. References . . . . . . . . . . . . . . . . . . . . . . . . . 16
10. References . . . . . . . . . . . . . . . . . . . . . . . . . 15 9.1. Normative References . . . . . . . . . . . . . . . . . . 16
10.1. Normative References . . . . . . . . . . . . . . . . . . 16 9.2. Informative References . . . . . . . . . . . . . . . . . 17
10.2. Informative References . . . . . . . . . . . . . . . . . 16 Appendix A. A Complete Example . . . . . . . . . . . . . . . . . 18
Appendix A. A Complete Example . . . . . . . . . . . . . . . . . 17 Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . . 20
Appendix B. Change Log . . . . . . . . . . . . . . . . . . . . . 19 Author's Address . . . . . . . . . . . . . . . . . . . . . . . . 20
B.1. Changes Between Revisions -09 and -10 . . . . . . . . . . 19
B.2. Changes Between Revisions -08 and -09 . . . . . . . . . . 19
B.3. Changes Between Revisions -07 and -08 . . . . . . . . . . 20
B.4. Changes Between Revisions -06 and -07 . . . . . . . . . . 20
B.5. Changes Between Revisions -05 and -06 . . . . . . . . . . 20
B.6. Changes Between Revisions -04 and -05 . . . . . . . . . . 20
B.7. Changes Between Revisions -03 and -04 . . . . . . . . . . 20
B.8. Changes Between Revisions -02 and -03 . . . . . . . . . . 20
B.9. Changes Between Revisions -01 and -02 . . . . . . . . . . 20
B.10. Changes Between Revisions -00 and -01 . . . . . . . . . . 21
Author's Address . . . . . . . . . . . . . . . . . . . . . . . . 21
1. Introduction 1. Introduction
The NETCONF protocol [RFC6241] uses XML [W3C.REC-xml-20081126] for The Network Configuration Protocol (NETCONF) [RFC6241] uses XML [XML]
encoding data in its Content Layer. Other management protocols might for encoding data in its Content Layer. Other management protocols
want to use other encodings while still benefiting from using YANG might want to use other encodings while still benefiting from using
[I-D.ietf-netmod-rfc6020bis] as the data modeling language. YANG [RFC7950] as the data modeling language.
For example, the RESTCONF protocol [I-D.ietf-netconf-restconf] For example, the RESTCONF protocol [RESTCONF] supports two encodings:
supports two encodings: XML (media type "application/yang.data+xml") XML (media type "application/yang.data+xml") and JavaScript Object
and JSON (media type "application/yang.data+json"). Notation (JSON) (media type "application/yang.data+json").
The specification of YANG 1.1 data modelling language The specification of the YANG 1.1 data modeling language [RFC7950]
[I-D.ietf-netmod-rfc6020bis] defines only XML encoding of data trees, defines only XML encoding of data trees, i.e., configuration data,
i.e., configuration data, state data, input/output parameters of RPC state data, input/output parameters of Remote Procedure Call (RPC)
operations or actions, and notifications. The aim of this document operations or actions, and notifications. The aim of this document
is to define rules for encoding the same data as JavaScript Object is to define rules for encoding the same data as JSON text [RFC7159].
Notation (JSON) text [RFC7159].
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 [RFC7950]:
o action, 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 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 module, o list
o module
o RPC operation, o RPC operation
o submodule. o submodule
The following terms are defined in [RFC6241]: The following terms are defined in [RFC6241]:
o configuration data, o configuration data
o notification, o notification
o state data. o state data
3. Properties of the JSON Encoding 3. Properties of the JSON Encoding
This document defines JSON encoding for YANG data trees and their This document defines JSON encoding for YANG data trees and their
subtrees. It is always assumed that the top-level structure in JSON- subtrees. It is always assumed that the top-level structure in JSON-
encoded data is an object. encoded data is an object.
Instances of YANG data nodes (leafs, containers, leaf-lists, lists, Instances of YANG data nodes (leafs, containers, leaf-lists, lists,
anydata and anyxml nodes) are encoded as members of a JSON object, anydata nodes, and anyxml nodes) are encoded as members of a JSON
i.e., name/value pairs. Section 4 defines how the name part is object, i.e., name/value pairs. Section 4 defines how the name part
formed, and the following sections deal with the value part. The is formed, and the following sections deal with the value part. The
encoding rules are identical for all types of data trees, i.e., encoding rules are identical for all types of data trees, i.e.,
configuration data, state data, parameters of RPC operations, configuration data, state data, parameters of RPC operations,
actions, and notifications. actions, and notifications.
With the exception of "anydata" encoding (Section 5.5), all rules in With the exception of "anydata" encoding (Section 5.5), all rules in
this document are also applicable to YANG 1.0 [RFC6020]. this document are also applicable to YANG 1.0 [RFC6020].
Unlike XML element content, JSON values carry partial type Unlike XML element content, JSON values carry partial type
information (number, string, boolean). The JSON encoding is defined information (number, string, boolean). The JSON encoding is defined
so that this information is never in conflict with the data type of so that this information is never in conflict with the data type of
the corresponding YANG leaf or leaf-list. the corresponding YANG leaf or leaf-list.
With the exception of anyxml and schema-less anydata nodes, it is 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 possible to map a JSON-encoded data tree to XML encoding as defined
in [I-D.ietf-netmod-rfc6020bis], and vice versa. However, such in [RFC7950], and vice versa. However, such conversions require the
conversions require the YANG data model to be available. YANG data model to be available.
In order to achieve maximum interoperability while allowing In order to achieve maximum interoperability while allowing
implementations to use a variety of existing JSON parsers, the JSON implementations to use a variety of existing JSON parsers, the JSON
encoding rules follow, as much as possible, the constraints of the encoding rules follow, as much as possible, the constraints of the
I-JSON restricted profile [RFC7493]. Section 7 discusses I-JSON I-JSON (Internet JSON) restricted profile [RFC7493]. Section 7
conformance in more detail. discusses I-JSON conformance in more detail.
4. Names and Namespaces 4. Names and Namespaces
A JSON object member name MUST be in one of the following forms: A JSON object member name MUST be in one of the following forms:
o simple - identical to the identifier of the corresponding YANG o simple - identical to the identifier of the corresponding YANG
data node; data node.
o namespace-qualified - the data node identifier is prefixed with o namespace-qualified - the data node identifier is prefixed with
the name of the module in which the data node is defined, the name of the module in which the data node is defined,
separated from the data node identifier by the colon character separated from the data node identifier by the colon character
(":"). (":").
The name of a module determines the namespace of all data node names 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, 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 then the namespace-qualified member name uses the name of the main
module to which the submodule belongs. module to which the submodule belongs.
ABNF syntax [RFC5234] of a member name is shown in Figure 1, where ABNF syntax [RFC5234] of a member name is shown in Figure 1, where
the production for "identifier" is defined in sec. 13 of the production for "identifier" is defined in Section 14 of
[I-D.ietf-netmod-rfc6020bis]. [RFC7950].
member-name = [identifier ":"] identifier member-name = [identifier ":"] identifier
Figure 1: ABNF production for a JSON member name. Figure 1: ABNF Production for a JSON Member Name
A namespace-qualified member name MUST be used for all members of a 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 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 data node and its parent node are different. In all other cases, the
simple form of the member name MUST be used. simple form of the member name MUST be used.
For example, consider the following YANG module: For example, consider the following YANG module:
module example-foomod { module example-foomod {
namespace "http://example.com/foomod"; namespace "http://example.com/foomod";
prefix "foomod"; prefix "foomod";
skipping to change at page 5, line 49 skipping to change at page 6, line 4
namespace "http://example.com/foomod"; namespace "http://example.com/foomod";
prefix "foomod"; prefix "foomod";
container top { container top {
leaf foo { leaf foo {
type uint8; type uint8;
} }
} }
} }
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 data: valid JSON-encoded configuration data:
{ {
"example-foomod:top": { "example-foomod:top": {
"foo": 54 "foo": 54
} }
} }
Note that the member of the top-level object uses the namespace- Note that the member of the top-level object uses the namespace-
qualified name but the "foo" leaf doesn't because it is defined in qualified name but the "foo" leaf doesn't because it is defined in
the same module as its parent container "top". the same module as its parent container "top".
Now, assume the container "top" is augmented from another module, Now, assume that the container "top" is augmented from another
"example-barmod": module, "example-barmod":
module example-barmod { module example-barmod {
namespace "http://example.com/barmod"; namespace "http://example.com/barmod";
prefix "barmod"; prefix "barmod";
import example-foomod { import example-foomod {
prefix "foomod"; prefix "foomod";
} }
augment "/foo:top" { augment "/foomod:top" {
leaf bar { leaf bar {
type boolean; type boolean;
} }
} }
} }
A valid JSON-encoded configuration data containing both leafs may Valid JSON-encoded configuration data containing both leafs may then
then look like this: look like this:
{ {
"example-foomod:top": { "example-foomod:top": {
"foo": 54, "foo": 54,
"example-barmod:bar": true "example-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. because its parent is defined in a different module.
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 "instance-identifier" types. The
same form of namespace-qualified name as defined above is then used. same form of namespace-qualified name as defined above is then used.
See Sections 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 data node instance is encoded as a name/value pair where the Every data node instance is encoded as a name/value pair where the
name is formed from the data node identifier using the rules of 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 Section 4. The value depends on the category of the data node, as
explained in the following subsections. explained in the following subsections.
Character encoding MUST be UTF-8. Character encoding MUST be UTF-8.
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).
skipping to change at page 8, line 15 skipping to change at page 8, line 34
5.3. The "leaf-list" Data Node 5.3. The "leaf-list" Data Node
A leaf-list is encoded as a name/array pair, and the array elements A leaf-list is encoded as a name/array pair, and the array elements
are values of some scalar type, which can be a string, number, are values of some scalar type, which can be a string, number,
literal "true" or "false", or the special array "[null]", depending literal "true" or "false", or the special array "[null]", depending
on the type of the leaf-list (see Section 6 for the type encoding on the type of the leaf-list (see Section 6 for the type encoding
rules). rules).
The ordering of array elements follows the same rules as the ordering The ordering of array elements follows the same rules as the ordering
of XML elements representing leaf-list entries in the XML encoding. of XML elements representing leaf-list entries in the XML encoding.
Specifically, the "ordered-by" properties (sec. 7.7.7 in Specifically, the "ordered-by" properties (Section 7.7.7 in
[I-D.ietf-netmod-rfc6020bis]) MUST be observed. [RFC7950]) MUST be observed.
Example: For the leaf-list definition Example: For the leaf-list definition
leaf-list foo { leaf-list foo {
type uint8; type uint8;
} }
the following is a valid JSON-encoded instance: the following is a valid JSON-encoded instance:
"foo": [123, 0] "foo": [123, 0]
5.4. The "list" Data Node 5.4. The "list" Data Node
A list instance is encoded as a name/array pair, and the array A list instance is encoded as a name/array pair, and the array
elements are JSON objects. elements are JSON objects.
The ordering of array elements follows the same rules as the ordering The ordering of array elements follows the same rules as the ordering
of XML elements representing list entries in the XML encoding. of XML elements representing list entries in the XML encoding.
Specifically, the "ordered-by" properties (sec. 7.7.7 in Specifically, the "ordered-by" properties (Section 7.7.7 in
[I-D.ietf-netmod-rfc6020bis]) MUST be observed. [RFC7950]) MUST be observed.
Unlike the XML encoding, where list keys are required to precede any Unlike the XML encoding, where list keys are required to precede any
other siblings within a list entry, and appear in the order specified other siblings within a list entry and appear in the order specified
by the data model, the order of members in a JSON-encoded list entry by the data model, the order of members in a JSON-encoded list entry
is arbitrary because JSON objects are fundamentally unordered is arbitrary because JSON objects are fundamentally unordered
collections of members. collections of members.
Example: For the list definition Example: For the list definition
list bar { list bar {
key foo; key foo;
leaf foo { leaf foo {
type uint8; type uint8;
} }
leaf baz { leaf baz {
type string; type string;
} }
} }
skipping to change at page 9, line 29 skipping to change at page 9, line 48
"baz": "zig" "baz": "zig"
}, },
{ {
"baz": "zag", "baz": "zag",
"foo": 0 "foo": 0
} }
] ]
5.5. The "anydata" Data Node 5.5. The "anydata" Data Node
Anydata data node serves as a container for an arbitrary set of nodes The anydata data node serves as a container for an arbitrary set of
that otherwise appear as normal YANG-modeled data. A data model for nodes that otherwise appear as normal YANG-modeled data. A data
anydata content may or may not be known at run time. In the latter model for anydata content may or may not be known at runtime. In the
case, converting JSON-encoded instances to the XML encoding defined latter case, converting JSON-encoded instances to the XML encoding
in [I-D.ietf-netmod-rfc6020bis] may be impossible. defined in [RFC7950] may be impossible.
An anydata instance is encoded in the same way as a container, i.e., An anydata instance is encoded in the same way as a container, i.e.,
as a value/object pair. The requirement that anydata content can be as a name/object pair. The requirement that anydata content can be
modeled by YANG implies the following rules for the JSON text inside modeled by YANG implies the following rules for the JSON text inside
the object: the object:
o It is valid I-JSON [RFC7493]. o It is valid I-JSON [RFC7493].
o All object member names satisfy the ABNF production in Figure 1. o All object member names satisfy the ABNF production in Figure 1.
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.
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": {
"event-class": "fault", "event-class": "fault",
skipping to change at page 10, line 41 skipping to change at page 11, line 9
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]
5.7. Metadata Objects 5.7. Metadata Objects
Apart from instances of YANG data nodes, a JSON document MAY contain Apart from instances of YANG data nodes, a JSON document MAY contain
special object members whose name starts with the "@" character special object members whose name starts with the "@" character
(COMMERCIAL AT). Such members are used for special purposes such as (COMMERCIAL AT). Such members are used for special purposes, such as
encoding metadata [I-D.ietf-netmod-yang-metadata]. Exact syntax and encoding metadata [RFC7952]. The exact syntax and semantics of such
semantics of such members are outside the scope of this document. members are outside the scope of this document.
6. Representing YANG Data Types in 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 types "int8", "int16", "int32", "uint8", "uint16" and A value of the "int8", "int16", "int32", "uint8", "uint16", or
"uint32" is represented as a JSON number. "uint32" type is represented as a JSON number.
A value of the "int64", "uint64" or "decimal64" type is represented A value of the "int64", "uint64", or "decimal64" type is represented
as a JSON string whose content is the lexical representation of the as a JSON string whose content is the lexical representation of the
corresponding YANG type 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]. [RFC7950].
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 the 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
precision range as strings, see sec. 2.2 in [RFC7493]. double-precision range [IEEE754-2008] as strings; see Section 2.2 in
[RFC7493].
6.2. The "string" Type 6.2. The "string" Type
A "string" value is represented as a JSON string, subject to JSON A "string" value is represented as a JSON string, subject to JSON
string encoding rules. string encoding rules.
6.3. The "boolean" Type 6.3. The "boolean" Type
A "boolean" value is represented as the corresponding JSON literal A "boolean" value is represented as the corresponding JSON literal
name "true" or "false". name "true" or "false".
6.4. The "enumeration" Type 6.4. The "enumeration" Type
An "enumeration" value is represented as a JSON string - one of the An "enumeration" value is represented as a JSON string -- one of the
names assigned by "enum" statements in YANG. names assigned by "enum" statements in YANG.
The representation is identical to the lexical representation of the The representation is identical to the lexical representation of the
"enumeration" type in XML, see sec. 9.6 in "enumeration" type in XML; see Section 9.6 in [RFC7950].
[I-D.ietf-netmod-rfc6020bis].
6.5. The "bits" Type 6.5. The "bits" Type
A "bits" value is represented as a JSON string - a space-separated A "bits" value is represented as a JSON string -- a space-separated
sequence of names of bits that are set. The permitted bit names are sequence of names of bits that are set. The permitted bit names are
assigned by "bit" statements in YANG. assigned by "bit" statements in YANG.
The representation is identical to the lexical representation of the The representation is identical to the lexical representation of the
"bits" type, see sec. 9.7 in [I-D.ietf-netmod-rfc6020bis]. "bits" type; see Section 9.7 in [RFC7950].
6.6. The "binary" Type 6.6. The "binary" Type
A "binary" value is represented as a JSON string - base64-encoding of A "binary" value is represented as a JSON string -- base64 encoding
arbitrary binary data. of arbitrary binary data.
The representation is identical to the lexical representation of the The representation is identical to the lexical representation of the
"binary" type in XML, see sec. 9.8 in [I-D.ietf-netmod-rfc6020bis]. "binary" type in XML; see Section 9.8 in [RFC7950].
6.7. The "leafref" Type 6.7. The "leafref" Type
A "leafref" value is represented using the same rules as the type of A "leafref" value is represented using the same rules as the type of
the leaf to which the leafref value refers. the leaf to which the leafref value refers.
6.8. The "identityref" Type 6.8. The "identityref" Type
An "identityref" value is represented as a string - the name of an An "identityref" value is represented as a string -- the name of an
identity. If the identity is defined in another module than the leaf identity. If the identity is defined in a module other than the leaf
node containing the identityref value, the namespace-qualified form node containing the identityref value, the namespace-qualified form
(Section 4) MUST be used. Otherwise, both the simple and namespace- (Section 4) MUST be used. Otherwise, both the simple and namespace-
qualified forms are permitted. qualified forms are permitted.
For example, consider the following schematic module: For example, consider the following schematic module:
module example-mod { module example-mod {
... ...
import ietf-interfaces { import ietf-interfaces {
prefix if; prefix if;
} }
import iana-if-type {
prefix ianaift;
}
... ...
leaf type { leaf type {
type identityref { type identityref {
base "if:interface-type"; base "if:interface-type";
} }
} }
} }
A valid instance of the "type" leaf is then encoded as follows: A valid instance of the "type" leaf is then encoded as follows:
skipping to change at page 13, line 33 skipping to change at page 14, line 12
"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.
When validating a value of the "union" type, the type information When validating a value of the "union" type, the type information
conveyed by the JSON encoding MUST also be taken into account. JSON conveyed by the JSON encoding MUST also be taken into account. JSON
syntax thus provides additional means for resolving union member type syntax thus provides additional means for resolving the member type
that are not available in XML encoding. of the union that are not available in XML encoding.
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 possible to set the In RESTCONF [RESTCONF], it is possible to set the value of "bar" in
value of "bar" in the following way when using the "application/ the following way when using the "application/yang.data+xml"
yang.data+xml" media type: media type:
<bar>13.5</bar> <bar>13.5</bar>
because the value may be interpreted as a string, i.e., the second
member type of the union. When using the "application/ because the value may be interpreted as a string, i.e., the
yang.data+json" media type, however, this is an error: second member type of the union. When using the
"application/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 that the value is supposed
a number rather than a string, and it is not a valid "uint16" value. to be a number rather than a string, and it is not a valid "uint16"
value.
Conversely, the value of Conversely, the value of
"bar": "1" "bar": "1"
is to be interpreted as a string. is to be interpreted as 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 Section 9.13.2 in [RFC7950]. However, the encoding of namespaces in
of namespaces in instance-identifier values follows the rules stated instance-identifier values follows the rules stated in Section 4,
in Section 4, namely: namely:
o The leftmost (top-level) data node name is always in the o The leftmost (top-level) data node name is always in the
namespace-qualified form. namespace-qualified form.
o Any subsequent data node name is in the namespace-qualified form o Any subsequent data node name is in the namespace-qualified form
if the node is defined in another module than its parent node, and if the node is defined in a module other than its parent node, and
the simple form is used otherwise. This rule also holds for node the simple form is used otherwise. This rule also holds for node
names appearing in predicates. 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-identifier value because the data nodes
"interfaces", "interface" and "name" are defined in the module "ietf- "interfaces", "interface", and "name" are defined in the module
interfaces", whereas "ipv4" and "ip" are defined in "ietf-ip". "ietf-interfaces", whereas "ipv4" and "ip" are defined in "ietf-ip".
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.
skipping to change at page 15, line 25 skipping to change at page 16, line 9
The JSON encoding defined in this document deviates from I-JSON only The JSON encoding defined in this document deviates from I-JSON only
in the representation of the "binary" type. In order to remain in the representation of the "binary" type. In order to remain
compatible with XML encoding, the base64 encoding scheme is used compatible with XML encoding, the base64 encoding scheme is used
(Section 6.6), whilst I-JSON recommends base64url instead. (Section 6.6), whilst I-JSON recommends base64url instead.
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 Section 17 of [RFC7950].
[I-D.ietf-netmod-rfc6020bis].
This document defines no mechanisms for signing and encrypting data This document defines no mechanisms for signing and encrypting data
modeled with YANG. Under normal circumstances, data security and modeled with YANG. Under normal circumstances, data security and
integrity is guaranteed by the management protocol in use, such as integrity are guaranteed by the management protocol in use, such as
NETCONF [RFC6241] or RESTCONF [I-D.ietf-netconf-restconf]. If it is NETCONF [RFC6241] or RESTCONF [RESTCONF]. If this is not the case,
not the case, external mechanisms, such as PKCS #7 [RFC2315] or JOSE external mechanisms, such as Public-Key Cryptography Standards (PKCS)
([RFC7515] and [RFC7516]), need to be considered. #7 [RFC2315] or JSON Object Signing and Encryption (JOSE) [RFC7515]
[RFC7516], need to be considered.
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 different types of vulnerabilities than their XML
counterparts. To minimize these new security risks, software on the counterparts. To minimize these new security risks, software on the
receiving side SHOULD reject all messages that do not comply to the receiving side SHOULD reject all messages that do not comply with the
rules of this document and reply with an appropriate error message to rules of this document and reply with an appropriate error message to
the sender. the sender.
9. Acknowledgments 9. References
The author wishes to thank Andy Bierman, Martin Bjorklund, Dean
Bogdanovic, Balazs Lengyel, Juergen Schoenwaelder and Phil Shafer for
their helpful comments and suggestions.
10. References
10.1. Normative References
[I-D.ietf-netmod-rfc6020bis] 9.1. Normative References
Bjorklund, M., "The YANG 1.1 Data Modeling Language",
draft-ietf-netmod-rfc6020bis-11 (work in progress),
February 2016.
[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, Requirement Levels", BCP 14, RFC 2119,
DOI 10.17487/RFC2119, March 1997, DOI 10.17487/RFC2119, March 1997,
<http://www.rfc-editor.org/info/rfc2119>. <http://www.rfc-editor.org/info/rfc2119>.
[RFC5234] Crocker, D., Ed. and P. Overell, "Augmented BNF for Syntax [RFC5234] Crocker, D., Ed. and P. Overell, "Augmented BNF for Syntax
Specifications: ABNF", STD 68, RFC 5234, Specifications: ABNF", STD 68, RFC 5234,
DOI 10.17487/RFC5234, January 2008, DOI 10.17487/RFC5234, January 2008,
<http://www.rfc-editor.org/info/rfc5234>. <http://www.rfc-editor.org/info/rfc5234>.
skipping to change at page 16, line 34 skipping to change at page 17, line 5
<http://www.rfc-editor.org/info/rfc6241>. <http://www.rfc-editor.org/info/rfc6241>.
[RFC7159] Bray, T., Ed., "The JavaScript Object Notation (JSON) Data [RFC7159] Bray, T., Ed., "The JavaScript Object Notation (JSON) Data
Interchange Format", RFC 7159, DOI 10.17487/RFC7159, March Interchange Format", RFC 7159, DOI 10.17487/RFC7159, March
2014, <http://www.rfc-editor.org/info/rfc7159>. 2014, <http://www.rfc-editor.org/info/rfc7159>.
[RFC7493] Bray, T., Ed., "The I-JSON Message Format", RFC 7493, [RFC7493] Bray, T., Ed., "The I-JSON Message Format", RFC 7493,
DOI 10.17487/RFC7493, March 2015, DOI 10.17487/RFC7493, March 2015,
<http://www.rfc-editor.org/info/rfc7493>. <http://www.rfc-editor.org/info/rfc7493>.
10.2. Informative References [RFC7950] Bjorklund, M., Ed., "The YANG 1.1 Data Modeling Language",
RFC 7950, DOI 10.17487/RFC7950, August 2016,
<http://www.rfc-editor.org/info/rfc7950>.
[I-D.ietf-netconf-restconf] 9.2. Informative References
Bierman, A., Bjorklund, M., and K. Watsen, "RESTCONF
Protocol", draft-ietf-netconf-restconf-10 (work in
progress), March 2016.
[I-D.ietf-netmod-yang-metadata] [IEEE754-2008]
Lhotka, L., "Defining and Using Metadata with YANG", IEEE, "IEEE Standard for Floating-Point Arithmetic",
draft-ietf-netmod-yang-metadata-07 (work in progress), IEEE 754-2008, DOI 10.1109/IEEESTD.2008.4610935, 2008,
March 2016. <http://standards.ieee.org/findstds/
standard/754-2008.html>.
[RESTCONF] Bierman, A., Bjorklund, M., and K. Watsen, "RESTCONF
Protocol", Work in Progress,
draft-ietf-netconf-restconf-16, August 2016.
[RFC2315] Kaliski, B., "PKCS #7: Cryptographic Message Syntax [RFC2315] Kaliski, B., "PKCS #7: Cryptographic Message Syntax
Version 1.5", RFC 2315, DOI 10.17487/RFC2315, March 1998, Version 1.5", RFC 2315, DOI 10.17487/RFC2315, March 1998,
<http://www.rfc-editor.org/info/rfc2315>. <http://www.rfc-editor.org/info/rfc2315>.
[RFC6020] Bjorklund, M., Ed., "YANG - A Data Modeling Language for [RFC6020] Bjorklund, M., Ed., "YANG - A Data Modeling Language for
the Network Configuration Protocol (NETCONF)", RFC 6020, the Network Configuration Protocol (NETCONF)", RFC 6020,
DOI 10.17487/RFC6020, October 2010, DOI 10.17487/RFC6020, October 2010,
<http://www.rfc-editor.org/info/rfc6020>. <http://www.rfc-editor.org/info/rfc6020>.
skipping to change at page 17, line 22 skipping to change at page 17, line 42
<http://www.rfc-editor.org/info/rfc7223>. <http://www.rfc-editor.org/info/rfc7223>.
[RFC7515] Jones, M., Bradley, J., and N. Sakimura, "JSON Web [RFC7515] Jones, M., Bradley, J., and N. Sakimura, "JSON Web
Signature (JWS)", RFC 7515, DOI 10.17487/RFC7515, May Signature (JWS)", RFC 7515, DOI 10.17487/RFC7515, May
2015, <http://www.rfc-editor.org/info/rfc7515>. 2015, <http://www.rfc-editor.org/info/rfc7515>.
[RFC7516] Jones, M. and J. Hildebrand, "JSON Web Encryption (JWE)", [RFC7516] Jones, M. and J. Hildebrand, "JSON Web Encryption (JWE)",
RFC 7516, DOI 10.17487/RFC7516, May 2015, RFC 7516, DOI 10.17487/RFC7516, May 2015,
<http://www.rfc-editor.org/info/rfc7516>. <http://www.rfc-editor.org/info/rfc7516>.
[W3C.REC-xml-20081126] [RFC7952] Lhotka, L., "Defining and Using Metadata with YANG",
Bray, T., Paoli, J., Sperberg-McQueen, M., Maler, E., and RFC 7952, DOI 10.17487/RFC7952, August 2016,
<http://www.rfc-editor.org/info/rfc7952>.
[XML] Bray, T., Paoli, J., Sperberg-McQueen, M., Maler, E., and
F. Yergeau, "Extensible Markup Language (XML) 1.0 (Fifth F. Yergeau, "Extensible Markup Language (XML) 1.0 (Fifth
Edition)", World Wide Web Consortium Recommendation REC- Edition)", World Wide Web Consortium Recommendation
xml-20081126, November 2008, REC-xml-20081126, November 2008,
<http://www.w3.org/TR/2008/REC-xml-20081126>. <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:
interfaces" and "ex-vlan" (the latter is an example module from "ietf-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
interfaces" module is supported. "ietf-interfaces" module is supported.
{ {
"ietf-interfaces:interfaces": { "ietf-interfaces:interfaces": {
"interface": [ "interface": [
{ {
"name": "eth0", "name": "eth0",
"type": "iana-if-type:ethernetCsmacd", "type": "iana-if-type:ethernetCsmacd",
"enabled": false "enabled": false
}, },
{ {
skipping to change at page 19, line 29 skipping to change at page 20, line 4
} }
}, },
{ {
"name": "lo1", "name": "lo1",
"type": "iana-if-type:softwareLoopback", "type": "iana-if-type:softwareLoopback",
"admin-status": "up", "admin-status": "up",
"oper-status": "up", "oper-status": "up",
"if-index": 1, "if-index": 1,
"statistics": { "statistics": {
"discontinuity-time": "2013-04-01T03:00:00+00:00" "discontinuity-time": "2013-04-01T03:00:00+00:00"
} }
} }
] ]
} }
} }
Appendix B. Change Log Acknowledgements
RFC Editor: Remove this section upon publication as an RFC.
B.1. Changes Between Revisions -09 and -10
o A sentence about signing and encrypting data was added, together
with informative references to RFCs 2315, 7515 and 7516.
B.2. Changes Between Revisions -08 and -09
o References to RFC 6241 term in the Terminology section were added.
o Prefixes in the example in Sec. 4 were changed so as to be
different from node names.
B.3. Changes Between Revisions -07 and -08
o Changed the names of example modules so that they start with
"example-".
B.4. Changes Between Revisions -06 and -07
o General permit on object members whose names start with "@".
B.5. Changes Between Revisions -05 and -06
o More text and a new example about resolving union-type values.
B.6. 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.7. Changes Between Revisions -03 and -04
o I-D.ietf-netmod-rfc6020bis is used as a normative reference
instead of RFC 6020.
o Removed noncharacters as an I-JSON issue because it doesn't exist
in YANG 1.1.
o Section about anydata encoding was added.
o Require I-JSON for anyxml encoding.
o Use ABNF for defining qualified name.
B.8. Changes Between Revisions -02 and -03
o Namespace encoding is defined without using RFC 2119 keywords.
o Specification for anyxml nodes was extended and clarified.
o Text about ordering of list entries was corrected.
B.9. Changes Between Revisions -01 and -02
o Encoding of namespaces in instance-identifiers was changed.
o Text specifying the order of array elements in leaf-list and list
instances was added.
B.10. Changes Between Revisions -00 and -01
o Metadata encoding was moved to a separate I-D, draft-lhotka-
netmod-yang-metadata.
o JSON encoding is now defined directly rather than via XML-JSON
mapping.
o The rules for namespace encoding has changed. This affect both
node instance names and instance-identifiers.
o I-JSON-related changes. The most significant is the string
encoding of 64-bit numbers.
o When validating union type, the partial type info present in JSON
encoding is taken into account.
o Added section about I-JSON compliance.
o Updated the example in appendix.
o Wrote Security Considerations.
o Removed IANA Considerations as there are none. The author wishes to thank Andy Bierman, Martin Bjorklund, Dean
Bogdanovic, Balazs Lengyel, Juergen Schoenwaelder, and Phil Shafer
for their helpful comments and suggestions.
Author's Address Author's Address
Ladislav Lhotka Ladislav Lhotka
CZ.NIC CZ.NIC
Email: lhotka@nic.cz Email: lhotka@nic.cz
 End of changes. 92 change blocks. 
280 lines changed or deleted 177 lines changed or added

This html diff was produced by rfcdiff 1.45. The latest version is available from http://tools.ietf.org/tools/rfcdiff/