MessagePack to JSON and back

Decode MessagePack (hex, base64 or a file) into readable JSON, or encode JSON as MessagePack.

loading MessagePack to JSON and back
About this tool

What is MessagePack, and why convert it to JSON?

MessagePack is a binary format that carries the same kinds of data as JSON: maps, lists, strings, numbers, booleans and null. It is more compact and faster to read by a program, which is why it appears in caches such as Redis, in RPC and messaging systems, in game servers and in some APIs. The price is that you cannot open it in a text editor. A message is a string of bytes such as 82 a1 61 01 a1 62 92 01 02, and nobody reads that by eye.

This tool converts in both directions. Paste MessagePack as hex or base64, or open a .msgpack file, and you get readable JSON. Paste JSON and you get the MessagePack bytes, shown as hex. It is meant for debugging: checking what a service really sent, preparing a test payload or comparing two encodings.

Details that matter when data is not trivial. Integers beyond 2^53, up to 64 bits, keep every digit, because JavaScript numbers would silently round them. Binary values can be shown as base64, as hex or as a list of numbers. Extension types are written as {"$ext": type, "hex": "..."}, except the standard timestamp, which becomes an ISO date. If a file holds several messages in a row, you get one JSON list. The bytes are decoded in your browser with a MessagePack library and are never sent anywhere.

How to convert MessagePack and JSON

  1. Choose the direction: "MessagePack → JSON" or "JSON → MessagePack".
  2. To decode, paste the bytes as hex or base64, or open a file. Hex may have spaces, 0x prefixes, commas or colons. Base64 may be URL-safe, with or without padding. Files up to 1 MB are accepted.
  3. Choose how binary values are written (base64, hex or numbers) and the indent (2, 4, tab or minified).
  4. To encode, paste JSON. The result appears as hex, and you can switch the "bytes as" option to base64.
  5. Read the counters under the result: bytes, number of values, and warnings about anything JSON cannot say.
  6. Copy the result or download it.

Examples

A small map

Hex input:

82 a1 61 01 a1 62 92 01 02

JSON output, minified:

{"a":1,"b":[1,2]}

The first byte, 82, means a map with two entries. a1 61 is the one-letter string a, and 92 starts a list of two items.

Binary in three forms

The bytes 81 a3 62 6b 79 c4 03 00 01 ff hold a map with a key bky and three bytes of binary data. The JSON depends on the "binary as" option:

{"bky":"AAH/"}
{"bky":"0001ff"}
{"bky":[0,1,255]}

These are base64, hex and numbers, in that order.

Extensions and timestamps

c7 03 05 01 02 03 is an extension of type 5 with the data 01 02 03:

{"$ext":5,"hex":"010203"}

The standard timestamp extension, d7 ff 77 35 94 00 65 53 f1 00, is shown as a date:

"2023-11-14T22:13:20.500Z"

Big integers going the other way

Encoding this JSON keeps the 64-bit integer as an integer, not as a rounded double:

{"big":9007199254740997,"n":4294967296,"m":-2147483649}
83 a3 62 69 67 cf 00 20 00 00 00 00 00 05 a1 6e cf 00 00 00 01 00 00 00 00 a1 6d d3 ff ff ff ff 7f ff ff ff

Decoding those bytes gives the same JSON back, with every digit of 9007199254740997.

Common mistakes

  • An odd number of hex digits. Each byte is two digits. 82a is rejected with a message about the count.
  • Text that is neither hex nor base64. Stray characters such as ! are reported. Remove spaces and line numbers that came from a log.
  • A base64 string that looks like hex. A text made only of the characters 0-9 and a-f with an even length is read as hex first. If your base64 happens to look like that, the result is wrong. Add padding or check the bytes with Base64.
  • A cut-off message. 92 01 promises two items and has one. The tool says the message ends too soon.
  • A byte that is not MessagePack. c1 is never used by the format, so it is reported as invalid.
  • Expecting JSON to hold everything. NaN and Infinity become null and are counted in a warning. Map keys that are not text are written as text, also with a warning.
  • Expecting exact bytes back. JSON has no binary type or timestamp, so a round trip through JSON does not restore them. Integers are written in the smallest integer type, and numbers with a fraction as 64-bit floats.

Frequently asked questions

Are 64-bit integers safe here?

Yes. They keep every digit in both directions. Many JSON tools round them to 53 bits without telling you.

What happens to extension types?

They are written as an object with $ext (the type number) and hex (the data). The standard timestamp is the exception, shown as an ISO date.

Can I decode several messages at once?

Yes. If the bytes hold more than one MessagePack value in a row, the output is a JSON list with all of them.

Where can I tidy up the JSON afterwards?

Use JSON Prettify to format or minify it. For a quick look at raw bytes, Hex to text is useful.

Report a problem