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 API.
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 most recent draft can be found at: https://datatracker.ietf.org/doc/draft-rundgren-cbor-core/
The following simple examples are supposed to give an idea of how CBOR::Core is to be used.
Although the examples build on a specific JavaScript solution,
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(cbor));
------------------------------
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(cbor));
------------------------------
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.
| 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 |
Updated: 2026-03-02