Re: [Cbor] Map keys?

Laurence Lundblade <> Tue, 07 May 2019 17:28 UTC

Return-Path: <>
Received: from localhost (localhost []) by (Postfix) with ESMTP id 039AA12022A for <>; Tue, 7 May 2019 10:28:13 -0700 (PDT)
X-Virus-Scanned: amavisd-new at
X-Spam-Flag: NO
X-Spam-Score: -1.898
X-Spam-Status: No, score=-1.898 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
Received: from ([]) by localhost ( []) (amavisd-new, port 10024) with ESMTP id X9qbgLLr69Mp for <>; Tue, 7 May 2019 10:28:09 -0700 (PDT)
Received: from ( []) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by (Postfix) with ESMTPS id A3CA6120255 for <>; Tue, 7 May 2019 10:28:08 -0700 (PDT)
Received: from [] ([]) by :SMTPAUTH: with ESMTPSA id O3srh6Mtev3PHO3sshBBWs; Tue, 07 May 2019 10:28:06 -0700
From: Laurence Lundblade <>
Message-Id: <>
Content-Type: multipart/alternative; boundary="Apple-Mail=_58C2AEB8-709C-416B-9118-8C2AB94CE181"
Mime-Version: 1.0 (Mac OS X Mail 11.5 \(3445.9.1\))
Date: Tue, 7 May 2019 10:28:04 -0700
In-Reply-To: <>
Cc: Felipe Gasper <>,
To: Carsten Bormann <>
References: <> <>
X-Mailer: Apple Mail (2.3445.9.1)
X-CMAE-Envelope: MS4wfIxo6gXfTZzjrn8peuD+sCy/7sbnE8kVtUm6FLZddjWulTaIbi5tzGn7KQZ3AjunIzChzNzrGBqUAN7x3PIv2uBUXML6b0d+y4SBkwZsB4AvDAig3sUb rl56VP7Pcq1JgGPPwdIc/M2iQJHvS5OHruxQrn4T2aUiX7HDp//WCE5YI6cE0qnhwolXp704VkyEvgs1jilzWbn/7exp+Gzx+1C+qxmvqTlBtLfVDHFhiT9h
Archived-At: <>
Subject: Re: [Cbor] Map keys?
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Concise Binary Object Representation \(CBOR\)" <>
List-Unsubscribe: <>, <>
List-Archive: <>
List-Post: <>
List-Help: <>
List-Subscribe: <>, <>
X-List-Received-Date: Tue, 07 May 2019 17:28:18 -0000

Here’s two examples of places where the types of map keys are restricted.

Section 1.4 has this CDDL limiting labels to integers and text strings:

   label = int / tstr

JSON “names” (“keys" in CBOR) can only be strings so any CBOR that translates has to limit keys.

I didn’t see any discussion of this in Appendix E in draft-ietf-cbor-cddl-08.txt. This seems important, at least to me for the EAT/RATS work where we want to use CDDL to describe both CBOR and JSON encodings. In particular we’d like to use integer keys in the CBOR encoding and need to resolve how that gets expressed in JSON.

It would be helpful to me to see more compelling real world examples of keys as arrays or maps. It seems like a cool thing to do in some ways, but in others it seems like a jump in complexity that should only be used if really necessary.


> On Apr 29, 2019, at 7:02 AM, Carsten Bormann <>; wrote:
> On Apr 29, 2019, at 15:39, Felipe Gasper <>; wrote:
>> Hello,
>> I’m looking at RFC 8392, which says:
>> ——-
>> In JSON, maps are called objects and only have one kind of map key: a string. CBOR uses strings, negative integers, and unsigned integers as map keys. 
> Well, it doesn’t say “and nothing else” :-)
> RFC 8392 is not intended to update RFC 7049, anyway.
>> The integers are used for compactness of encoding and easy comparison. The inclusion of strings allows for an additional range of short encoded values to be used.
>> ——-
>> While this doesn’t directly say per se that CBOR _only_ uses strings and integers as map keys, the implication seems strong. I don’t see any such limitation in the CBOR RFC.
>> Does CBOR intend, then, to restrict map keys to only major types 0, 1, and 3?
> There is no such intention.
> Indeed, major types 0/1 and 3 are the most often used map keys (probably followed by 2).  But there is nothing wrong with 7 (false, true, …), 6 (tagged data), or the containers (4, 5) etc. as map keys.
> This may be elucidated a bit more by draft-ietf-cbor-cddl-08.txt (in RFC editor queue), section 2, which distinguishes two kinds of map usage: “structs” (where indeed 0/1 and 3 are usually most convenient), and “tables”, where the ability to use any CBOR data item as a map key is vital.
> Grüße, Carsten
> _______________________________________________
> CBOR mailing list