JSON to Bencode
Convert JSON to Bencode encoding. Automatically sorts dictionary keys per BitTorrent BEP 0003 and exports downloadable .torrent files.
Converting JSON to Bencode
This tool converts any standard JSON data structure into Bencode (BitTorrent encoding). Bencode is a compact, type-safe serialization format used extensively across peer-to-peer networks, BitTorrent trackers, and DHT (Distributed Hash Table) nodes.
When encoding to Bencode, this tool guarantees compliance with the official BitTorrent BEP 0003 specification, ensuring that dictionary keys are sorted lexicographically by raw byte values.
How JSON Maps to Bencode
| JSON Data Type | JSON Example | Bencode Output | Encoding Rule |
|---|---|---|---|
| Integer / Number | 42 | i42e | Enclosed between 'i' and 'e'. Non-integer numbers are floored. |
| String | "hello" | 5:hello | UTF-8 byte length, colon, followed by raw string bytes. |
| Array | ["a", 1] | l1:ai1ee | Enclosed between 'l' and 'e'. |
| Object | {"b": 1, "a": 2} | d1:ai2e1:bi1ee | Enclosed between 'd' and 'e'. Keys are automatically sorted by raw byte order. |
| Binary Hex String | "[hex] a1b2" | 2:<binary> | Tag with '[hex]' to output raw binary bytes (e.g. for SHA-1 piece hashes). |
Why Dictionary Key Sorting Matters
In JSON, the order of object keys does not matter semantically: {"a": 1, "b": 2} and {"b": 2, "a": 1} are considered equivalent.
However, in BitTorrent, torrent clients compute the SHA-1 cryptographic hash of the bencoded info dictionary to produce the Info-Hash. If keys were allowed in arbitrary order, two clients encoding the same data would compute different info-hashes and fail to find peers. Bencode solves this by requiring keys to be sorted in binary lexicographical order. Our encoder automatically sorts all dictionary keys for you.
Frequently Asked Questions
Can I download the result as a real .torrent file?
Yes. Click the .torrent button above to download an authentic binary .torrent file ready to be opened in any BitTorrent client like qBittorrent, Transmission, or Deluge.
How do I encode binary hashes for torrent pieces?
Prefix your hex string with [hex] (for example: "pieces": "[hex] 0123456789abcdef..."). Our encoder will parse the hex string and write the raw binary bytes into the Bencode stream.
Is my data sent to any server?
No. All encoding, byte array building, and file downloads happen 100% locally in your browser.