Subject: [netmod] RFC 7951 - JSON encoding of empty lists

From: Jack Rickard <[email-masked]>
Date: Tue, 29 Mar 2022 14:21:10 +0000

Hi,

I think I've found an ambiguity in RFC 7951, and I'd like your input on what was intended and what the best behaviour to exhibit is.

Section 5.3 and 5.4 of RFC 7951 - JSON Encoding of Data Modeled with YANG (ietf.org)<https://datatracker.ietf.org/doc/html/rfc7951#section-5.3> describe the encoding of leaf-lists and lists, however it's unclear how an empty list should be encoded. Should it be encoded as:

  1.  An empty array: {"list": []}
  2.  A missing field: {}

I've seen libraries go either way, libyang only accepts 2 but the python yangson library accepts both (I'm not sure which is the default).

Thanks,
Jack Rickard
he/him
Software Engineer
[email-masked]<mailto:[email-masked]>

[Microsoft Logo]

---

From: Kent Watsen <[email-masked]>
Date: Tue, 29 Mar 2022 17:14:13 +0000

#1 is an empty list (or leaf-list).  This is what you want.

#2 is a list containing one element, which is an empty container (or, in Python term's, an empty 'dict').

Yanglint 1.x used to accept #1, kinks are being worked out on the 2.x branch.

Kent // contributor

> On Mar 29, 2022, at 10:21 AM, Jack Rickard <jack.rickard=[email-masked]> wrote:
> 
> Hi,
>  
> I think I’ve found an ambiguity in RFC 7951, and I’d like your input on what was intended and what the best behaviour to exhibit is.
>  
> Section 5.3 and 5.4 of RFC 7951 - JSON Encoding of Data Modeled with YANG (ietf.org) <https://datatracker.ietf.org/doc/html/rfc7951#section-5.3> describe the encoding of leaf-lists and lists, however it’s unclear how an empty list should be encoded. Should it be encoded as:
> An empty array: {“list”: []}
> A missing field: {}
>  
> I’ve seen libraries go either way, libyang only accepts 2 but the python yangson library accepts both (I’m not sure which is the default).
>  
> Thanks,
> Jack Rickard 
> he/him 
> Software Engineer 
> [email-masked] <mailto:[email-masked]> 
> 
>  
>  
> _______________________________________________
> netmod mailing list
> [email-masked] <mailto:[email-masked]>
> https://www.ietf.org/mailman/listinfo/netmod <https://www.ietf.org/mailman/listinfo/netmod>

---

From: Jack Rickard <[email-masked]>
Date: Tue, 29 Mar 2022 18:19:18 +0000

Hi Kent,

Thanks very much for the response. However, I'm slightly worried you've misunderstood my examples, and as I've been fighting in the #1 corner I want to make sure I give #2 a fair chance.

Given this schema:
module test {
  prefix "test";
  namespace "urn:test";

  container test {
    leaf foo {type string;}
    leaf-list bar {type string;}
    leaf baz {type string;}
  }
}

Is this valid (#1):
{
        "test:test": {
                "foo": "test1",
                "bar": [],
                "baz": "test2"
        }
}

and is this valid (#2):
{
        "test:test": {
                "foo": "test1",
                "baz": "test2"
        }
}

To make sure I didn't miss something I verified this with yanglint 0.16.105 (what ubuntu gave me), and that accepts #2 but not #1 (it rejects #1 with err : Invalid JSON data (unexpected value). (/test:test/bar)).
To be really clear this is accepted:
{
        "test:test": {
                "foo": "test1",
                "bar": ["test3"],
                "baz": "test2"
        }
}

Thanks,
Jack

________________________________
From: Kent Watsen <[email-masked]>
Sent: 29 March 2022 18:14
To: Jack Rickard <[email-masked]>
Cc: [email-masked] <[email-masked]>; [email-masked] <[email-masked]>
Subject: Re: [netmod] RFC 7951 - JSON encoding of empty lists

Kent // contributor

On Mar 29, 2022, at 10:21 AM, Jack Rickard <jack.rickard=[email-masked]<mailto:jack.rickard=[email-masked]>> wrote:

Hi,

Section 5.3 and 5.4 of RFC 7951 - JSON Encoding of Data Modeled with YANG (ietf.org)<https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fdatatracker.ietf.org%2Fdoc%2Fhtml%2Frfc7951%23section-5.3&data=04%7C01%7Cjack.rickard%40microsoft.com%7Ca33f2d22f70f4de7a87808da11a79ae4%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637841709447361395%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=2jqJW1VVJyft9CVC3T5xCgXvlt4Zsd7c7mdtBrKSpdM%3D&reserved=0> describe the encoding of leaf-lists and lists, however it’s unclear how an empty list should be encoded. Should it be encoded as:

  1.  An empty array: {“list”: []}
  2.  A missing field: {}

Thanks,
Jack Rickard
he/him
Software Engineer

_______________________________________________
netmod mailing list
[email-masked]<mailto:[email-masked]>
https://www.ietf.org/mailman/listinfo/netmod<https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.ietf.org%2Fmailman%2Flistinfo%2Fnetmod&data=04%7C01%7Cjack.rickard%40microsoft.com%7Ca33f2d22f70f4de7a87808da11a79ae4%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637841709447361395%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=RJxmETMYeLjdtqejd%2BsfV6jkjjAuQAxZ%2FeQkf14lZT0%3D&reserved=0>

---

From: Kent Watsen <[email-masked]>
Date: Tue, 29 Mar 2022 20:30:21 +0000

Hi Jack,

Yes, indeed, I did misunderstand your original #2.

Between an empty list node appearing (as just "[ ]") versus not appearing at all, I do not think that the JSON encoding is defined, and so tooling should accept either encoding, IMO.   [FWIW, XML has only one encoding].

Personally, I initially preferred #1 (because it is more self-describing), but implementation-details drove me to #2.

Kent // contributor

> On Mar 29, 2022, at 2:19 PM, Jack Rickard <[email-masked]> wrote:
> 
> Hi Kent,
> 
>> On Mar 29, 2022, at 10:21 AM, Jack Rickard <jack.rickard=[email-masked] <mailto:jack.rickard=[email-masked]>> wrote:
>> 
>> Hi,
>>  
>> Section 5.3 and 5.4 of RFC 7951 - JSON Encoding of Data Modeled with YANG (ietf.org) <https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fdatatracker.ietf.org%2Fdoc%2Fhtml%2Frfc7951%23section-5.3&data=04%7C01%7Cjack.rickard%40microsoft.com%7Ca33f2d22f70f4de7a87808da11a79ae4%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637841709447361395%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=2jqJW1VVJyft9CVC3T5xCgXvlt4Zsd7c7mdtBrKSpdM%3D&reserved=0> describe the encoding of leaf-lists and lists, however it’s unclear how an empty list should be encoded. Should it be encoded as:
>> https://www.ietf.org/mailman/listinfo/netmod <https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.ietf.org%2Fmailman%2Flistinfo%2Fnetmod&data=04%7C01%7Cjack.rickard%40microsoft.com%7Ca33f2d22f70f4de7a87808da11a79ae4%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637841709447361395%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=RJxmETMYeLjdtqejd%2BsfV6jkjjAuQAxZ%2FeQkf14lZT0%3D&reserved=0>

---

From: Ladislav Lhotka <[email-masked]>
Date: Wed, 30 Mar 2022 09:53:26 +0200

Hi,

>   1.  An empty array: {"list": []}

Both variants are equivalent and should be supported by tools and libraries.

I can understand though that tools supporting both XML and JSON representations tend to prefer #2 because #1 doesn't exist in XML.

Also note that #1 isn't really of much use, as entire list and leaf-list instances aren't even resources/endpoints in RESTCONF API - e.g. it's not possible to GET the entire list.

Lada

> [email-masked]
> https://www.ietf.org/mailman/listinfo/netmod

-- 
Ladislav Lhotka
Head, CZ.NIC Labs
PGP Key ID: 0xB8F92B08A9F76C67

---

From: Kent Watsen <[email-masked]>
Date: Wed, 30 Mar 2022 10:38:28 +0000

> Also note that #1 isn't really of much use, as entire list and leaf-list instances aren't even resources/endpoints in RESTCONF API - e.g. it's not possible to GET the entire list.

True, but the “list-pagination” drafts (adoption-call in NETCONF) seek to change this. 

K.