Re: [Json] On flat vs nested JSON encoding style

Carsten Bormann <> Thu, 04 February 2016 15:39 UTC

Return-Path: <>
Received: from localhost ( []) by (Postfix) with ESMTP id 343CC1B31A7 for <>; Thu, 4 Feb 2016 07:39:21 -0800 (PST)
X-Virus-Scanned: amavisd-new at
X-Spam-Flag: NO
X-Spam-Score: -1.9
X-Spam-Status: No, score=-1.9 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001] autolearn=ham
Received: from ([]) by localhost ( []) (amavisd-new, port 10024) with ESMTP id nlvaTNJ7fcsx for <>; Thu, 4 Feb 2016 07:39:19 -0800 (PST)
Received: from ( []) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by (Postfix) with ESMTPS id 5302C1B319E for <>; Thu, 4 Feb 2016 07:39:19 -0800 (PST)
Received: from ( []) by (Postfix) with ESMTP id E35ABC5A7B; Thu, 4 Feb 2016 16:39:17 +0100 (CET)
X-Virus-Scanned: Debian amavisd-new at
Received: from ([IPv6:::ffff:]) by ( [::ffff:]) (amavisd-new, port 10024) with ESMTP id eB4LaLd4On6u; Thu, 4 Feb 2016 16:39:16 +0100 (CET)
Received: from nar.local ( []) (Authenticated sender: by (Postfix) with ESMTPSA id 4B851C5AB0; Thu, 4 Feb 2016 16:39:15 +0100 (CET)
Message-ID: <>
Date: Thu, 04 Feb 2016 16:39:13 +0100
From: Carsten Bormann <>
User-Agent: Postbox 4.0.8 (Macintosh/20151105)
MIME-Version: 1.0
To: Anders Rundgren <>
References: <> <>
In-Reply-To: <>
X-Enigmail-Version: 1.2.3
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Archived-At: <>
Cc: Phillip Hallam-Baker <>, JSON WG <>
Subject: Re: [Json] On flat vs nested JSON encoding style
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: "JavaScript Object Notation \(JSON\) WG mailing list" <>
List-Unsubscribe: <>, <>
List-Archive: <>
List-Post: <>
List-Help: <>
List-Subscribe: <>, <>
X-List-Received-Date: Thu, 04 Feb 2016 15:39:21 -0000

Anders Rundgren wrote:
> Anyway, isn't CBOR what people are targeting for constrained devices?

Yes, but the desire to be able to do sequential (as opposed to
DOM-based) processing goes beyond constrained devices.

But talking about those:

The original design of SenML <draft-jennings-core-senml-04.txt> had a
top level map (what is called "object" in JavaScript, but then arrays
are also objects in JavaScript) of the form:

{ "metadata1": "value",
  "metadata2": 4711,
  "contents": [
     ... potentially many measurements
     ... where the interpretation of those
     ... depends on the metadata.

This looks deceptively sequential on a napkin, and it creates no
problems for a DOM-based receiver implementation (until the measurements
don't fit into memory any more).  For an implementation that tries to do
sequential processing, this structure is a big problem:  The metadata
may occur before or after the measurement array, depending on the whims
of the encoder, so you may not have what you need to process the
measurements sequentially at the place they occur.

Requiring the encoder to send data in a particular sequence is
theoretically possible, but in practice just means you lose that part of
the ecosystem that happens not to do that, and often you don't even get
a guarantee (order may be dictated by hash values that may be randomized
in a good implementation).

So we are moving SenML to something like:

[ { ... metadata blob ... },
  ... measurements ...

(the details are still being discussed).

Of course, in CBOR we could do:

{ { ... metadata blob ... }:
  [ measurements ]

i.e., use the metadata as the key for the map.  Which is essentially
what PHB is proposing, but that works in JSON only if the metadata
happens to be a single string (which is the case in the example given by

Back to the discussion about representation style:


{ "foo":
  { ... }


{ "type": "foo",

may or may not be compatible with the "struct"-style (see section 2 of
<draft-greevenbosch-appsawg-cbor-cddl-07.txt> for a definition of
various styles of using JSON-like data models), depending on whether
"foo" happens to be a constant in your implementation or you expect to
encounter new values as you go along.

Grüße, Carsten