Protobuf, MessagePack, CBOR, BSON API

Decode and encode Protobuf (with a .proto or schemaless), MessagePack, CBOR and BSON to and from JSON. Input base64, hex or a file; output base64 and hex.

POSThttps://apibox.io.vn/v1/binary-formats

Pick a format (protobuf, msgpack, cbor, bson) and an action. To decode, send the bytes as data (base64 or hex, detected automatically; spaces, 0x and colons are ignored) or upload a file; the result is JSON. To encode, send the value as json; the result has base64, hex and the size. to converts a decoded value straight into another format (for example MessagePack → CBOR).

Protobuf: give the schema in proto (proto2 / proto3 text, with nested messages, enums, maps, oneofs, packed repeated fields, 64-bit integers kept exact as strings) and message_type (e.g. shop.Order). Field names may be the .proto names or lowerCamelCase; enums accept names or numbers; bytes are base64. defaults=true fills missing fields with their default values, enums_as_numbers=true returns enum numbers. Without proto, the wire data is decoded schemalessly: each field number with its wire type and possible readings (unsigned, signed zigzag, float / double, UTF-8 string or nested message).

In JSON, binary values appear as {"$bytes": "<base64>"}, CBOR tags as {"$tag": n, "value": …}, MessagePack extensions as {"$ext": type, "$bytes": …}, big integers as strings and timestamps as ISO dates; the same forms are accepted when encoding. BSON uses MongoDB Extended JSON ($oid, $date, $numberLong…, relaxed by default, ejson=canonical for canonical). Size limit: 2 MB of binary data.

Parameters

NameInTypeRequiredDefault
formatbodystringyesprotobuf, msgpack, cbor or bson.
actionbodystringnodecode or encode (default: encode when json is given).
databodystringnoDecode: the bytes as base64 or hex.
filebodyfilenoDecode: the binary file (multipart).
input_encodingbodystringnoForce base64 or hex for data.
jsonbodyobjectnoEncode: the value (JSON object / array, or a JSON string).
protobodystringnoProtobuf: the .proto schema text.
message_typebodystringnoProtobuf: message name, with package (e.g. shop.Order).
defaultsbodybooleannofalseProtobuf decode: include fields with default values.
enums_as_numbersbodybooleannofalseProtobuf decode: enums as numbers instead of names.
ejsonbodystringnorelaxedBSON: relaxed or canonical Extended JSON.
tobodystringnoDecode: also re-encode into msgpack, cbor or bson.

Example

curl -X POST "https://apibox.io.vn/v1/binary-formats" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"format":"protobuf","proto":"syntax = \"proto3\";\nmessage Test1 { int32 a = 1; }","data":"089601"}'

Response

{
  "format": "protobuf",
  "action": "decode",
  "input_bytes": 3,
  "message_type": "Test1",
  "json": {
    "a": 150
  }
}

Use cases

  • Read a Protobuf payload from a webhook or gRPC log without compiling stubs
  • Debug MessagePack or CBOR messages from IoT devices
  • Convert a MongoDB BSON dump document to readable JSON
  • Build test fixtures in Protobuf or MessagePack from JSON

FAQ

Can I decode Protobuf without the .proto file?

Yes. The schemaless mode shows field numbers, wire types and the plausible values of each field, and opens nested messages. Names and exact types need the schema.

Are imports in .proto files supported?

Only a single self-contained schema: paste the imported messages into the same text. google.protobuf well-known types are treated as ordinary messages.

How are 64-bit integers handled?

They are read and written exactly: as decimal strings in JSON (Protobuf int64 / uint64, MessagePack and CBOR big integers) and as $numberLong in BSON when they do not fit in a JavaScript number.

Related APIs

Start with 1,000 free requests every month. Get free API key →