CBOR and MessagePack
Convert JSON to CBOR (RFC 8949) or MessagePack bytes and back, with byte strings, dates, big integers, tags and extension types kept in a JSON form, deterministic CBOR for signatures, and strict limits on malformed data. Typical uses: decode sensor and IoT messages, shrink the readings sent over a slow link, read the messages of a queue or a cache written in MessagePack.
cbor encodecbor encodecbor decodecbor decodemsgpack encodemsgpack encodemsgpack decodemsgpack decode

cbor encode <json>


Description

    JSON to CBOR, in base64

Parameters

    json:   The JSON value - String - required
admin
cbor encode "{\"device\": \"TH-204\", \"t\": 21.5, \"h\": 48, \"ok\": true, \"at\": \"2026-11-11T08:30:00Z\"}"
mentdb
pWZkZXZpY2VmVEgtMjA0YXT5TWBhaBgwYm9r9WJhdHQyMDI2LTExLTExVDA4OjMwOjAwWg==
Bytes and a date tag
admin
cbor encode "{\"id\": {\"@bytes\": \"AQID\"}, \"since\": {\"@tag\": 1, \"@value\": 1794385800}}"
mentdb
omJpZEMBAgNlc2luY2XBGmr0J4g=

cbor encode <json> <json_params>


Description

    JSON to CBOR with parameters: output (base64, base64url, hex), deterministic (false), int_keys (false), floats (shortest, 64), bytes (base64, base64url, hex: the form of the @bytes values), typed (true: read the @ markers), max_depth (64)

Parameters

    json:   The JSON value - String - required
    json_params:   The parameters, as a JSON object - String - required
admin
cbor encode "[1, [2, 3], -1000, 1.5, 100000.0, 18446744073709551616]" "{\"output\": \"hex\"}"
mentdb
86018202033903e7f93e00fa47c35000c249010000000000000000
A COSE key: integer keys, sorted
admin
cbor encode "{\"1\": 2, \"3\": -7, \"-1\": 1, \"-2\": {\"@bytes\": \"65eda5a12577c2bae829437fe338701a10aaa375e1bb5b5de108de439c08551d\"}}" "{\"output\": \"hex\", \"deterministic\": true, \"int_keys\": true, \"bytes\": \"hex\"}"
mentdb
a401020326200121582065eda5a12577c2bae829437fe338701a10aaa375e1bb5b5de108de439c08551d
Used in use cases (1 recipe)

    IoT & sensor engineer › Shrink sensor messages with CBOR and MessagePack, and sign the same bytes every time
Often used with

    cbor decode  ·  msgpack encode  ·  string hash  ·  string length

cbor decode <cbor_data>


Description

    CBOR (base64) to JSON

Parameters

    cbor_data:   The CBOR bytes, in base64 - String - required
admin
cbor decode "pWZkZXZpY2VmVEgtMjA0YXT5TWBhaBgwYm9r9WJhdHQyMDI2LTExLTExVDA4OjMwOjAwWg=="
mentdb
{"device": "TH-204", "t": 21.5, "h": 48, "ok": true, "at": "2026-11-11T08:30:00Z"}

cbor decode <cbor_data> <json_params>


Description

    CBOR to JSON with parameters: input (base64, hex), typed (false), tags (convert, keep), bytes (base64, base64url, hex), sequence (false: true reads a CBOR sequence, RFC 8742, as a JSON array), max_depth (64), max_items (1000000)

Parameters

    cbor_data:   The CBOR bytes - String - required
    json_params:   The parameters, as a JSON object - String - required
admin
cbor decode "84c074323031332d30332d32315432303a30343a30305ac11a514b67b0c249010000000000000000c48221196ab3" "{\"input\": \"hex\"}"
mentdb
["2013-03-21T20:04:00Z", "2013-03-21T20:04:00Z", 18446744073709551616, 273.15]
Indefinite lengths and a byte string, typed
admin
cbor decode "bf6346756ef563416d74216269645f42010243030405ffff" "{\"input\": \"hex\", \"typed\": true}"
mentdb
{"Fun": true, "Amt": -2, "id": {"@bytes": "AQIDBAU="}}
Tags kept as they are
admin
cbor decode "c11a514b67b0" "{\"input\": \"hex\", \"tags\": \"keep\"}"
mentdb
{"@tag": 1, "@value": 1363896240}
A CBOR sequence
admin
cbor decode "0102a1616103" "{\"input\": \"hex\", \"sequence\": true}"
mentdb
[1, 2, {"a": 3}]
Truncated data: an array of 3 items with 2
admin
cbor decode "830102" "{\"input\": \"hex\"}"
mentdb
ERROR: Sorry, an error appears (the array at byte 1 declares 3 items but only 2 bytes remain).
Used in use cases (1 recipe)

    IoT & sensor engineer › Shrink sensor messages with CBOR and MessagePack, and sign the same bytes every time
Often used with

    cbor encode  ·  msgpack encode  ·  string hash  ·  string length

msgpack encode <json>


Description

    JSON to MessagePack, in base64

Parameters

    json:   The JSON value - String - required
admin
msgpack encode "{\"device\": \"TH-204\", \"t\": 21.5, \"h\": 48, \"ok\": true, \"at\": \"2026-11-11T08:30:00Z\"}"
mentdb
haZkZXZpY2WmVEgtMjA0oXTLQDWAAAAAAAChaDCib2vDomF0tDIwMjYtMTEtMTFUMDg6MzA6MDBa

msgpack encode <json> <json_params>


Description

    JSON to MessagePack with parameters: output (base64, base64url, hex), floats (64, shortest), int_keys (false), bytes (base64, base64url, hex), typed (true: read the @bytes, @timestamp and @ext markers), max_depth (64)

Parameters

    json:   The JSON value - String - required
    json_params:   The parameters, as a JSON object - String - required
admin
msgpack encode "{\"at\": {\"@timestamp\": \"2026-11-11T08:30:00.250Z\"}, \"raw\": {\"@bytes\": \"AQID\"}, \"x\": {\"@ext\": 5, \"@data\": \"YWJj\"}}" "{\"output\": \"hex\"}"
mentdb
83a26174d7ff3b9aca006af42788a3726177c403010203a178c70305616263
Floats in 32 bits when exact
admin
msgpack encode "[1.5, 0.1]" "{\"output\": \"hex\", \"floats\": \"shortest\"}"
mentdb
92ca3fc00000cb3fb999999999999a
Used in use cases (1 recipe)

    IoT & sensor engineer › Shrink sensor messages with CBOR and MessagePack, and sign the same bytes every time
Often used with

    cbor decode  ·  cbor encode  ·  string hash  ·  string length

msgpack decode <msgpack_data>


Description

    MessagePack (base64) to JSON

Parameters

    msgpack_data:   The MessagePack bytes, in base64 - String - required
admin
msgpack decode "haZkZXZpY2WmVEgtMjA0oXTLQDWAAAAAAAChaDCib2vDomF0tDIwMjYtMTEtMTFUMDg6MzA6MDBa"
mentdb
{"device": "TH-204", "t": 21.5, "h": 48, "ok": true, "at": "2026-11-11T08:30:00Z"}

msgpack decode <msgpack_data> <json_params>


Description

    MessagePack to JSON with parameters: input (base64, hex), typed (false), timestamps (iso, keep: {"@timestamp": ...}), bytes (base64, base64url, hex), sequence (false: true reads values one after the other, as a JSON array), max_depth (64), max_items (1000000)

Parameters

    msgpack_data:   The MessagePack bytes - String - required
    json_params:   The parameters, as a JSON object - String - required
admin
msgpack decode "83a26174d7ff3b9aca006af42788a3726177c403010203a178c70305616263" "{\"input\": \"hex\", \"typed\": true}"
mentdb
{"at": {"@timestamp": "2026-11-11T08:30:00.250Z"}, "raw": {"@bytes": "AQID"}, "x": {"@ext": 5, "@data": "YWJj"}}
Two values in a stream
admin
msgpack decode "01a26f6b" "{\"input\": \"hex\", \"sequence\": true}"
mentdb
[1, "ok"]
0xc1 is never used
admin
msgpack decode "c1" "{\"input\": \"hex\"}"
mentdb
ERROR: Sorry, an error appears (the byte 1 (0xc1) is never used in MessagePack).