Skip to content
ToolShedby Wasim Shaikh

Bencode to JSON

Convert Bencode data and .torrent files to JSON. Inspect torrent metadata, piece hashes, and tracker URLs. Runs 100% in your browser.

Bencode to JSONJSON to Bencode

Drop your .torrent or .bencode file here, or click to browse

100% private. Files are processed entirely in your browser and never sent to a server.

179 chars
Syntax Error at offset 177:Unexpected byte "Ã" (0xc3)

What is Bencode?

Bencode (pronounced bee-encode) is the serialization format created by Bram Cohen for the BitTorrent protocol. It is used to encode metadata in .torrent files, tracker scrape messages, and BitTorrent peer exchange (PEX) packets.

Unlike JSON, Bencode has native support for arbitrary binary strings (such as 20-byte SHA-1 hash sequences for torrent verification) and enforces strict canonical ordering of dictionary keys so that cryptographic hashes of metadata are universally deterministic.

The 4 Bencode Data Types

1. Integers (i...e)

Enclosed between i and e. For example, i42e represents 42, and i-15e represents -15. Leading zeros (such as i03e) and negative zero (i-0e) are invalid.

2. Byte Strings (<length>:<data>)

Prefix length in ASCII bytes followed by a colon and the raw byte content. For example, 4:spam represents the string "spam".

3. Lists (l...e)

Enclosed between l and e. Can contain any bencoded elements. For example, l4:spami42ee maps to ["spam", 42].

4. Dictionaries (d...e)

Enclosed between d and e with alternating string keys and values. Keys must be sorted in raw byte order. For example, d3:bar4:spam3:fooi42ee maps to {"bar": "spam", "foo": 42}.

Understanding .torrent File Structure

Every .torrent file is a Bencode dictionary containing at minimum:

  • announce: The URL string of the primary BitTorrent tracker.
  • announce-list (optional): Tiered backup list of tracker URLs.
  • creation date: Unix timestamp of when the torrent was minted.
  • info: A sub-dictionary containing file descriptions. The SHA-1 hash of the raw bencoded info dictionary is the famous Torrent Info-Hash.
  • info.piece length: Number of bytes per verification chunk (e.g., 262,144 for 256 KB).
  • info.pieces: Concatenated 20-byte binary SHA-1 hashes for every piece. Our converter renders these as hex strings (e.g. [hex] 1a2b...) so you can safely view and copy them.

Frequently Asked Questions

Are my torrent files uploaded to a remote server?

No. All decoding and parsing runs completely in your web browser using HTML5 FileReader and JavaScript typed arrays. Your files never leave your device.

How does the tool handle binary torrent pieces in JSON?

JSON strings cannot reliably store arbitrary binary bytes like null characters (\0). Our decoder auto-detects non-text byte strings and displays them as clean [hex] or [base64] strings, keeping the output valid JSON.

Can I convert the JSON back to Bencode?

Yes! Use our companion tool JSON to Bencode to convert JSON structures back into valid, byte-sorted Bencode strings or downloadable .torrent files.