Re: [netmod] JSON to XML lossy conversion

Ladislav Lhotka <ladislav.lhotka@nic.cz> Thu, 16 July 2020 15:31 UTC

Return-Path: <ladislav.lhotka@nic.cz>
X-Original-To: netmod@ietfa.amsl.com
Delivered-To: netmod@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id 72E1A3A0AC5 for <netmod@ietfa.amsl.com>; Thu, 16 Jul 2020 08:31:04 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -1.897
X-Spam-Level:
X-Spam-Status: No, score=-1.897 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_NONE=0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
Received: from mail.ietf.org ([4.31.198.44]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 8Pnq31jBhBOZ for <netmod@ietfa.amsl.com>; Thu, 16 Jul 2020 08:31:02 -0700 (PDT)
Received: from trail.lhotka.name (trail.lhotka.name [77.48.224.143]) by ietfa.amsl.com (Postfix) with ESMTP id 7C2453A0AC4 for <netmod@ietf.org>; Thu, 16 Jul 2020 08:31:00 -0700 (PDT)
Received: by trail.lhotka.name (Postfix, from userid 109) id 3D8978600CA; Thu, 16 Jul 2020 17:23:18 +0200 (CEST)
Received: from localhost (unknown [172.29.2.100]) by trail.lhotka.name (Postfix) with ESMTPSA id 2A99986005D; Thu, 16 Jul 2020 17:23:17 +0200 (CEST)
From: Ladislav Lhotka <ladislav.lhotka@nic.cz>
To: Michal Vaško <mvasko@cesnet.cz>, netmod <netmod@ietf.org>
In-Reply-To: <15dd-5f106300-3d-41094600@245675998>
References: <15dd-5f106300-3d-41094600@245675998>
Mail-Followup-To: Michal Vaško <mvasko@cesnet.cz>, netmod <netmod@ietf.org>
Date: Thu, 16 Jul 2020 17:30:57 +0200
Message-ID: <87mu3z4gum.fsf@nic.cz>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
Archived-At: <https://mailarchive.ietf.org/arch/msg/netmod/vuCEVtFqISy-ZguH7z2I3AgrW6Y>
Subject: Re: [netmod] JSON to XML lossy conversion
X-BeenThere: netmod@ietf.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: NETMOD WG list <netmod.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/options/netmod>, <mailto:netmod-request@ietf.org?subject=unsubscribe>
List-Archive: <https://mailarchive.ietf.org/arch/browse/netmod/>
List-Post: <mailto:netmod@ietf.org>
List-Help: <mailto:netmod-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/netmod>, <mailto:netmod-request@ietf.org?subject=subscribe>
X-List-Received-Date: Thu, 16 Jul 2020 15:31:04 -0000

Hi Michal,

Michal Vaško <mvasko@cesnet.cz> writes:

> Hello,
> it seems that there are cases when YANG data represented in JSON include more information than when converted to XML. Example:
>
> YANG:
>
> module a {
>   leaf l {
>     type union {
>       type string;
>       type uint8;
>     }
>   }
> }
>
> JSON:
>
> {
>   "a:l": 20
> }
>
> These data will be parsed as the leaf "l" of type "uint8" based on the JSON specs [1]. Then, when printed again
>
> XML:
>
> <a:l>20<a:l>
>
> this XML would be parsed as leaf "l" of type "string".
>
> Similar problem occurs also for boolean. So I am just wondering, is this a known bug/feature, is it intentional? It is true that applications usually choose one format and stick to it but it is not a requirement and I can see this having possibly quite nasty consequences.

This has already been discussed several times in the past, for example in this thread:

https://mailarchive.ietf.org/arch/browse/netmod/?gbt=1&index=dqNrvzOV2Ur6RoX6rTW-ZzsV65g

In my view, if it is a bug, it is in the design of the union type in YANG - there is no general way to signal the actual union member type for an instance. I believe it is a good thing that some encodings allow for at least partial signalling.

Note that similar issues may arise even more often in CBOR, see e.g. comments for section 5.12 in

https://mailarchive.ietf.org/arch/msg/core/Zrb2yhSSdlouS6PI9qfsA1bsDB4/

Lada



>
> Regards,
> Michal
>
> [1] https://tools.ietf.org/html/rfc7951#section-6.10
>
> _______________________________________________
> netmod mailing list
> netmod@ietf.org
> https://www.ietf.org/mailman/listinfo/netmod

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