Bencode decoder
Decode BitTorrent bencode (BEP 3) data — strings, integers, lists and dictionaries — with key-order validation, a JSON view and a collapsible tree showing byte offsets.
Runs in your browserEvery computation happens in your browser — your data never leaves this device.
Decoded value
Type bencode data to decode it
Selected node
JSON view
Byte strings that are not UTF-8 are written as h'…'; integers outside the safe range stay strings.
What this tool does
- Inspect the metainfo structure of a .torrent file — the name, piece length and announce fields inside the info dictionary — when a torrent opens but refuses to download.
- Verify that dictionary keys are in strict ascending byte order as BEP 3 requires; a spec-compliant client rejects a torrent whose keys are out of order.
- Locate a field by byte offset: every tree row shows the start offset and byte length, so you can jump straight to the spot in a hex editor.
- Convert bencode into JSON for follow-up work with a script or jq.
Example
Input
d3:cow3:moo4:spam4:eggse
Output
{
"cow": "moo",
"spam": "eggs"
}This is the classic example from BEP 3: 24 bytes and 3 nodes (the root dictionary plus two strings). In text mode the input is encoded as UTF-8; if the data contains non-UTF-8 bytes, switch to hex mode and paste them there.
Frequently asked questions
Why does my torrent fail to parse?
Usually because the dictionary keys are not sorted in byte order, or the data is truncated (only half the file was copied). BEP 3 treats key order as a hard requirement, so the tool reports “Not valid bencode data” rather than being lenient; if the bytes came from somewhere else, check completeness in hex mode first.
How are byte strings that are not UTF-8 shown?
bencode is a byte protocol and allows any bytes. The tool tries UTF-8 first and shows the decoded text when it succeeds; otherwise it prints hex as `h'…'`, in the JSON view as well. An encoding mismatch never blocks parsing.
What about integers beyond the JavaScript safe range?
Integers are displayed as decimal strings in the tree with no rounding at all. When converting to JSON, only values within ±2^53−1 become JSON numbers; anything larger stays a string so precision is never silently lost.
How is this different from the CBOR viewer?
Both are binary serialisation formats but the rules differ completely: bencode only has strings, integers, lists and dictionaries, and dictionary keys must be sorted; CBOR has eight major types plus indefinite-length containers, floats and tags. Use the CBOR viewer for IoT or COSE data, and this one for torrent files.
Does decoding touch the network?
No. The whole decoder runs locally in your browser with no network requests, and the data you paste never leaves the page.
Keywords:bencodebittorrenttorrentbep 3decodemetainfoBencode 解码种子文件磁力链接字典键排序序列化解析