This repository contains resources associated with the CBOR::Core project.
The purpose of CBOR::Core is providing a specification that
can be supported by quite different platforms, while maintaining a high level of interoperability,
including with respect to an API that is underpinning CBOR::Core.
CBOR::Core has also been described as "a better JSON" 😊
Interoperability is achieved by:
- Compatibility with the CBOR base specification: RFC 8949
- Deterministic encoding, while optionally offering decoding support for "legacy" CBOR
- Strict type-checking at the API level as well as by the decoding process
The CBOR::Core API supports the following primitives:
| Primitive | Variants |
|---|---|
| Fixed-size integers | Int8, Uint8, Int16, Uint16, Int32, Uint32, Int64, Uint64, Int128, Uint128 |
| Unlimited-size integers | BigInt |
| Floating-point values | Float16, Float32, Float64 |
| Booleans | True, False |
| Text-strings | String |
| Byte-strings | Bytes |
In addition to arrays [] and maps {}, the CBOR::Core API also supports
CBOR date-time types, Ìnt53, CBOR Null, CBOR "tags", and CBOR Simple.
The following simple examples are intended to illustrate how the CBOR::Core API can be used.
Although the examples build on a specific JavaScript implementation,
other implementations are supposed to be quite similar with respect to usage.
const TEMPERATURE_KEY = CBOR.Int(1);
const GREETINGS_KEY = CBOR.Int(2);
let cbor = CBOR.Map()
.set(TEMPERATURE_KEY, CBOR.Float(45.7))
.set(GREETINGS_KEY, CBOR.String("Hi there!")).encode();
console.log(cbor.toHex());
------------------------------
a201fb4046d9999999999a0269486920746865726521Note: there are no requirements "chaining" objects like above.
let map = CBOR.decode(cbor); // cbor: from the encoding example
console.log(map.toString()); // Diagnostic notation
----------------------------------------------------
{
1: 45.7,
2: "Hi there!"
}
console.log('Value=' + map.get(TEMPERATURE_KEY).getFloat64());
--------------------------------------------------------------
Value=45.7To simplify logging, documentation, and debugging, a conforming
CBOR::Core implementation should also include support for the
text-based CBOR-format known as "Diagnostic Notation".
However, diagnostic notation can also be used as input for creating CBOR based test data and configuration files from text:
let cbor = CBOR.fromDiagnostic(`{
# Comments are also permitted
1: 45.7,
2: "Hi there!"
}`).encode();
console.log(cbor.toHex());
------------------------------
a201fb4046d9999999999a0269486920746865726521On https://cyberphone.github.io/cbor-core/playground/ you will find a simple Web application, permitting testing a conformant encoder, decoder, and diagnostic notation implementation.
For maintaining cross-platform interoperability, CBOR::Core mandates
a fixed (aka "deterministic") encoding of CBOR objects.
To shield developers from having to know the inner workings of deterministic encoding,
conforming CBOR::Core implementations perform
all necessary transformations automagically. This for example means that if the
set() operations
in the Encoding Example were swapped, the generated CBOR would remain the same.
The most recent draft can be found at: https://datatracker.ietf.org/doc/draft-rundgren-cbor-core/
| Language | URL |
|---|---|
| JDK 21+ | https://github.com/cyberphone/openkeystore |
| Android/Java | https://github.com/cyberphone/android-cbor |
| JavaScript | https://github.com/cyberphone/CBOR.js#main |
| Python 3 | https://github.com/cyberphone/CBOR.py#main |
| Rust | https://crates.io/crates/cbor-core |
Updated: 2026-11-21