Skip to main content

Bencode Encoder — JSON to BitTorrent Bencode

A free bencode encoder online: paste JSON and get BitTorrent bencode instantly. This JSON to bencode converter encodes live as you type — with a type-annotated tree view, a byte-level hex dump, true UTF-8 byte-length string encoding, and canonical dictionary key sorting. No sign-up, no server: 100% in your browser.

Looking to go the other way? Try our bencode decoder to turn bencoded data back into readable JSON.

Encode JSON to bencode

Type or paste any JSON value — string, integer, array, or object. Encoding is live; floats, booleans, and null are rejected with the exact JSON path, because bencode supports only four types.


        
        
      
Cannot encode.

Bencode format in 60 seconds

Bencode is the encoding defined by BEP 3 for the BitTorrent protocol. It has exactly four types — no floats, no booleans, no null:

TypeSyntaxExample
Integeri<n>ei42e → 42
Byte string<len>:<data>4:spam → "spam" (len = UTF-8 bytes)
Listl<items>el4:spami42ee → ["spam", 42]
Dictionaryd<pairs>e, keys sortedd3:bar4:spam3:fooi42ee → {"bar": "spam", "foo": 42}
Dictionary keys are always sorted lexicographically by raw UTF-8 bytes, as BEP 3 requires for a canonical encoding. For example {"b": 1, "a": 2} encodes as d1:ai2e1:bi1ee — key "a" first, no matter the order you typed. This is what makes a torrent's infohash deterministic: every client bencoding the same info dictionary produces the identical SHA-1 hash.
Watch the byte lengths. Bencode string lengths count UTF-8 bytes, not characters. "café" is 4 characters but 5 UTF-8 bytes, so it encodes as 5:café. This encoder measures every string with TextEncoder (true UTF-8), so multi-byte text can never corrupt your output.

Bencode encoder FAQ

What is bencode?

Bencode (pronounced "bee-encode") is the data encoding defined by BEP 3 for the BitTorrent protocol. It supports exactly four types: integers as i<n>e (for example, i42e), byte strings as <length>:<data> (for example, 4:spam), lists as l...e (for example, l4:spami42ee), and dictionaries as d...e with keys sorted in byte order (for example, d3:bar4:spam3:fooi42ee). Torrent files (.torrent) are simply bencoded dictionaries.

How do I convert JSON to bencode with this tool?

Paste or type any JSON value — a string, integer, array, or object — into the input box and the bencoded output appears instantly, with no button to press. Switch tabs to inspect the same bytes as a hex dump or as an annotated tree that shows each value's bencode type and its encoded fragment. Use Copy for the raw text or Download to save the exact bytes as a .bencode file.

Why does the tool say the rocket emoji is 4 bytes long?

Bencode string lengths count UTF-8 bytes, not JavaScript characters. The rocket emoji \ud83d\ude80 looks like 2 characters to JavaScript (UTF-16 code units) but is 4 bytes in UTF-8 (F0 9F 9A 80), so it encodes as 4:<4 bytes>. Getting this right matters: torrent clients hash the exact bytes, so a length counted in characters would produce a corrupt file. This encoder always measures with TextEncoder, i.e. true UTF-8 byte length.

How are dictionary keys ordered in bencode output?

Dictionary keys are sorted lexicographically by their raw UTF-8 bytes — this is required by BEP 3 for a canonical encoding. For example, {"b": 1, "a": 2} encodes as d1:ai2e1:bi1ee, with "a" first regardless of the order you typed them. Canonical ordering is what makes a torrent's infohash deterministic: every client that bencodes the same info dictionary gets the identical SHA-1 hash.

Can bencode encode floats, booleans, or null?

No. Bencode has only four types — integers, byte strings, lists, and dictionaries — so there is no representation for 1.5, true, or null. This tool rejects such values instead of silently coercing them, and the error message shows the exact JSON path of the offending value (for example, $.settings.ratio) so you can fix it. If you need them, encode 1/0 for booleans or use a string.

What is the difference between bencode and JSON?

JSON is a human-readable text format with objects, arrays, strings, numbers, booleans, and null. Bencode is a compact, deterministic, byte-oriented format with only integers, byte strings, lists, and dictionaries — no whitespace, no floats, no booleans, no null. Bencode was designed for BitTorrent metadata where exact bytes matter (hashing, signatures), while JSON is designed for readability and general data exchange.

How is bencode used in torrent files?

A .torrent file is a bencoded dictionary containing keys like announce (the tracker URL) and info (a nested dictionary describing the files, piece length, and piece hashes). A BitTorrent client computes the torrent's infohash by taking the SHA-1 hash of the bencoded info dictionary — which is exactly why canonical key ordering and byte-accurate string lengths matter. Try the torrent-like example above to see a realistic structure encoded.

Is my data sent to a server when I use this encoder?

No. This bencode encoder runs entirely in your browser — the JSON you paste never leaves your device, there is no account or sign-up, and the page keeps working offline after it loads. That also means you can safely encode private torrent metadata or internal data structures without privacy concerns.

Related tools

Free tool by NRTechStudio