TXT · Text & Data tools

JSON to Bencode

Output encoding
JSON
Bencode bytes
Bencodeformat0 Bwritten0 Bas JSON0chars out
Open the full binary format decoder with every format and the encoder

Shareable link

Settings are written to the URL as you change them. Nothing differs from the defaults yet.

Encode a structure

Paste JSON and the bencode bytes appear as hex or Base64. The grammar is small enough to read by eye: i42e is an integer, 4:spam is a string prefixed by its length, l...e is a list, and d...e is a dictionary.

{"cow": "moo", "spam": "eggs"} becomes d3:cow3:moo4:spam4:eggse, which is legible in the output pane without a decoder.

Sorted keys are part of the format

Bencode is canonical by design. Dictionary keys are sorted as raw byte strings, and a client that hashes the info dictionary to produce an infohash depends on that order being reproducible. Two encoders that disagree on ordering produce two different infohashes for the same torrent.

Keys here are sorted before writing, so re-encoding a decoded structure returns the same bytes.

What cannot be encoded

There is no null, no true, and no 1.5. Torrent metadata works around this: flags are stored as 0 and 1, and there are no floating point fields anywhere in the format. When the encoder stops, it names the path, so $.info.private points straight at the value to change.

Binary values are the other limit. Piece hashes and peer lists are raw bytes, not text, and a JSON source has no way to carry them without a hex or Base64 wrapper that bencode would then store as literal characters.

Frequently Asked Questions

Bencode has four types: integer, byte string, list, and dictionary. There is no null, no boolean, and no fractional number. The error names the path that failed so the source can be fixed.

Yes. The spec requires keys in sorted order, and torrent clients compare the encoded bytes, so writing them in JSON order would produce a file other clients read differently.

It writes any bencoded structure, including one shaped like torrent metadata. Piece hashes are raw binary and cannot be expressed in a JSON source, so a real torrent still needs its pieces string added by a client.

Pages locked to one format

Full Binary Format Decoder tool

Explore Our Tools

Browse all tools