Monetary values in CBOR

This document describes two tags for the serialization of money amounts in Concise Binary Object Representation (CBOR, RFC7049).

Common rules

Currency codes

Currency codes should be valid 3-letter codes from the ISO 4217 standard. CBOR encoders and decoders may reject invalid or unknown currency codes.

Numbers

Multiple ways of serializing a quantity of money are allowed:

Tag 77111: Money

The string representation is composed of a currency code (three uppercase letters) followed by a number. It must match the Perl-compatible regular expression [A-Z]{3}[0-9]+(\.[0-9]+)?.

Examples:

The array representation is composed of two or three elements:

  1. The currency code (major type 3).
  2. The quantity of money (in any of the allowed formats listed in the previous section).
  3. A map (major type 5) of additional attributes attached to this amount of money. The map’s keys should be text strings (major type 3) and a decoder should return an error if it encounters an attribute that it cannot attach to the re-created object.

Examples:

Tag 77112: MoneyBasket

The map’s keys should be either currency codes or the special value "attrs".

If the key is a currency code, then the value must be a number serialized in one of the allowed formats previously listed.

If the key is "attrs", then the value must be a map (major type 5) of additional attributes attached to this basket. The map’s keys should be text strings (major type 3) and a decoder should return an error if it encounters an attribute that it cannot attach to the re-created object.

Examples:

Implementations

Trivia

The tag number 77111 was chosen because it represents the first two letters of the word “Money” in ASCII.

Author and License

The present document was written by Charly Coste (changaco at changaco.oy.lc) on 2019-02-22 and released on the same day under the terms of the CC0 Public Domain Dedication.