MessagePack to JSON Converter

MessagePack to JSON

About MessagePack

What is MessagePack?

MessagePack is a compact binary serialization format. This converter handles null, booleans, strings, numbers, arrays, string-keyed maps, binary data, timestamps, signed and unsigned 64-bit integers, and extension values through explicit JSON wrappers.

When to use MessagePack?

Use MessagePack when both endpoints implement compatible MessagePack and agree on timestamp and extension type codes. Preserve the $binary, $numberLong, $uint64, $date, and $messagePackExt wrappers when moving values through JSON, or type information will be lost.

MessagePack in JavaScript

import { encode, decode } from '@msgpack/msgpack';

const value = { hello: 'world' };
const bytes = encode(value);
const hex = Array.from(bytes, (byte) => byte.toString(16).padStart(2, '0')).join('');

console.log(hex);
// Output: 81a568656c6c6fa5776f726c64

console.log(decode(bytes));
// Output: { hello: 'world' }
				

MessagePack in Go

package main

import (
	"fmt"

	"github.com/vmihailenco/msgpack/v5"
)

func main() {
	value := map[string]any{"hello": "world"}
	encoded, _ := msgpack.Marshal(value)
	fmt.Printf("%x\n", encoded)
	// Output: 81a568656c6c6fa5776f726c64

	var decoded map[string]any
	_ = msgpack.Unmarshal(encoded, &decoded)
	fmt.Println(decoded["hello"])
	// Output: world
}
				

MessagePack in PHP

<?php
require 'vendor/autoload.php';

use MessagePack\MessagePack;

$value = ['hello' => 'world'];
$encoded = MessagePack::pack($value);
echo bin2hex($encoded) . PHP_EOL;
// Output: 81a568656c6c6fa5776f726c64

$decoded = MessagePack::unpack($encoded);
echo $decoded['hello'] . PHP_EOL;
// Output: world