DevTools Logo

MessagePack & CBOR Inspector

MessagePack & CBOR Inspector

Encode JSON or decode pasted bytes, and see every byte with its offset, type and value.

Runs in your browser
Try an example

JSON input

1 line · 27 chars

Byte inspection

18 bytes · MessagePack · JSON 27 bytes

Hex dump

82 a7 63 6f 6d 70 61 63 74 c3 a6 73 63 68 65 6d 61 00

Byte tree

@082fixmap
@1a7fixstr"compact"
@9c3truetrue
@10a6fixstr"schema"
@1700positive fixint0

Notation

{"compact": true, "schema": 0}

Decoded JSON

{
  "compact": true,
  "schema": 0
}

A client-side binary format inspector with JSON input, format selection, hex dump, and recursive byte tree visualization.

Examples

MessagePack reference map

Input
encodeMessagePack({ compact: true, schema: 0 })
Output
"82 a7 63 6f 6d 70 61 63 74 c3 a6 73 63 68 65 6d 61 00"

A two-entry fixmap with fixstr keys, a true boolean, and a zero positive fixint — deterministic key order.

CBOR negative integer

Input
decodeCbor(new Uint8Array([0x20]))
Output
{ value: -1 }

Major type 1 with additional information 0 decodes as -1 - 0 = -1.

About this tool

MessagePack / CBOR Inspector encodes and decodes both binary JSON formats: encodeMessagePack/decodeMessagePack cover positive/negative fixints, fixstr versus str8/16/32 at the 32-byte boundary, fixarray/fixmap, and nil/bool/uint/int/float64 scalars, while encodeCbor/decodeCbor cover major types 0 (unsigned), 1 (negative), 3 (text string), 4 (array), 5 (map), plus false/true/null and float64. inspectJson parses JSON text and returns bytes, hex, value, tree, and error in one call.

Every decode returns a byte-offset tree: ByteTreeNode entries carry offset, header byte, hex slice, type label, and children, so map keys, string payloads, and container boundaries can be traced byte by byte. Map keys sort deterministically (localeCompare) on encode, making reference vectors byte-stable.

Failures are explicit: truncated inputs throw "Truncated input", trailing bytes after a value throw, unsupported bytes or CBOR lengths throw, and inspectJson surfaces JSON parse errors in the error field instead of throwing.

How to use this tool

  1. Pick a format

    Call inspectJson(text, "msgpack" or "cbor") or the encode/decode pair directly for byte-level control.

  2. Read the tree

    Walk tree children for offset, header, hex, and type at each node to audit the encoding layout.

  3. Check boundaries

    Watch 31- versus 32-byte strings (fixstr vs str8) and fixint edges (-32/-33, 127) when sizing payloads.

  4. Handle errors

    Catch truncation and trailing-byte throws, or read inspectJson's error field for bad JSON input.

Use cases

Auditing binary payload sizes

Compare MessagePack versus CBOR byte counts for the same JSON before picking a wire format.

Debugging decoder failures

Use offset trees to find the exact byte where a truncated or foreign payload breaks.

Teaching binary JSON encodings

Show how fixstr, fixmap, and major-type headers map JSON values to bytes.

Common mistakes

Mistake:Assuming 32-byte strings stay fixstr.

Fix:Fixstr tops out at 31 bytes — 32-byte strings switch to the 0xd9 str8 prefix with a length byte.

Mistake:Expecting CBOR and MessagePack bytes to match.

Fix:The formats use different headers (e.g. nil is 0xc0 vs 0xf6) — only decoded values are comparable.

Frequently asked questions

What does this tool do?

It encodes and decodes MessagePack and CBOR with encodeMessagePack/decodeMessagePack, encodeCbor/decodeCbor, and one-shot inspectJson — every decode returns a byte-offset tree with header, hex, type, and children per node.

How do fixstr and negative fixint boundaries work?

Strings up to 31 bytes use fixstr (0xa0 | length); 32-byte strings switch to the 0xd9 str8 prefix. Integers -32 to -1 encode as single negative-fixint bytes (e.g. -1 is 0xff), while -33 falls back to int8.

Is my payload uploaded or stored?

No. Encoding, decoding, and tree building run entirely in your browser.

Why did decoding throw, or why did inspectJson report an error?

Truncated buffers throw "Truncated input" and trailing bytes throw as well — check the tree offsets for the break point. An inspectJson error field means the JSON text itself failed to parse.

References & standards