Every scholar’s passage in Bayan Library starts as a JSON file from turath.io, and the field names in that file are Arabic diacritics. This is how we read them, the one name that turned out to be a digit, and why our decoder refuses a book rather than half read it.
A format that is not an API
Each book is one file, https://files.turath.io/books-v3/{id}.json. turath.io publishes no terms or license, and the scrambled names are a sign the files are not meant as an API. So the code that decodes them lives in one file, src/turath.ts, which an official export from Nuqayah would replace. We have run it on 25 of the 275 tafsirs. The rest wait for Nuqayah’s permission.
Names as diacritics
The top level of Ibn Kathir’s file, book 1503, holds three names: U+064B (ARABIC FATHATAN, a haraka), U+0659 (ARABIC ZWARAKAY, also a mark) and pages. Abridged, with the names written as escapes so they can be seen:
{"\u064b": {"\u064c": 1503,"\u064d": "تفسير ابن كثير - ط ابن الجوزي","\u0653": "2.0","\u0658": 59},"\u0659": {"\u0660": [1, 2, 3, … 58]},"pages": [ … ]}
The key is in turath’s own app code: each name in a fixed list becomes U+064B plus its position. pages is not in the list and is written plainly, as are the fields of each page and heading.
// src/turath.tsconst V1 ="meta id name type printed pdf_links info info_long version author_id cat_id date_built author_page_start indexes volumes headings print_pg_to_pg volume_bounds page_map page_headings non_author".split(" ",);const V2 = [...V1.slice(0, 9), "source", ...V1.slice(9)];const FIRST = 0x064b; const keyOf = (names: string[], name: string) => String.fromCodePoint(FIRST + names.indexOf(name));
Two lists, told apart by one name
There are two lists. The newer one puts source after version, so from author_id on, every name moves one place, and one character means different things in different books. U+0654 is author_id in at-Tabari’s file and source in تفسير قتادة, where it holds "local". U+0658 is indexes at the top of at-Tabari’s file and author_page_start inside Ibn Kathir’s, where it holds 59.
| Name | Older list | Newer list |
|---|---|---|
source | none | U+0654 |
author_id | U+0654 | U+0655 |
author_page_start | U+0657 | U+0658 |
indexes | U+0658 | U+0659 |
non_author | U+065F | U+0660 |
Looking for source does not tell the lists apart: Ibn Kathir’s file uses the newer list and has none. Where indexes landed does. Plain means not scrambled, U+0658 the older list, U+0659 the newer, and anything else is refused.
const names = Object.hasOwn(raw, "indexes")? null: Object.hasOwn(raw, keyOf(V1, "indexes"))? V1: Object.hasOwn(raw, keyOf(V2, "indexes"))? V2: undefined;
The name that is a digit
The older list has 21 names, and its last, non_author, lands on U+065F, the end of the block of harakat and marks. The newer list has 22, so its non_author lands on U+0660. That is not a mark. It is ARABIC-INDIC DIGIT ZERO, ٠.
This was a real bug in our decoder, now fixed. It is worth telling for how quietly a bug like it fails. The decoder passes any name outside the scrambled range through untouched, as it must for pages. A range that ended at U+065F would let the zero through too, and non_author would read as absent. An absent list is read as empty, and empty is normal: at-Tabari’s is empty. Nothing would throw. A newer file would just lose its list of the pages that are not the author’s. In Ibn Kathir that list is the first 58 positions, the publisher’s and the editor’s introductions, which author_page_start marks as well. Only the list can mark pages after the author’s first, such as the last 49 positions of العذب النمير, under ثبت مصادر التعليق.
Now any one-character name from U+064B to U+066B is taken as scrambled, and a name past the end of its list is refused. Tests read non_author at U+0660 in an excerpt of Ibn Kathir’s file, and refuse a U+0660 added to an excerpt of at-Tabari’s, where it names nothing.
What is inside a book
Under the names, a book is pages, each { text, vol, page }, and a table of contents, indexes.headings, each { title, level, page }, where page is a position in pages, from 1. Here is position 4,644 of the 4,710 in Ibn Kathir’s pages, exactly as turath stores it:
{"text": "القيامة-: يابن آدم، حملتك على الخيل والإبل، وزوجتك النساء، وجعلتك تَرْبَع (^١) وترأس (^٢)، فأين شكر ذلك؟ " (^٣). تفرد به من هذا الوجه.\nآخر تفسير سورة "التكاثر"، ولله الحمد [والمنّة] (^٤).\n_________\n(^١) أي: تركتك مستريحًا لا تحتاج إلى مشقة وتعب (شرح صحيح مسلم للنووي ١٨/ ١٠٣).\n(^٢) أي: جعلتك رئيس القوم وكبيرهم (المصدر السابق).\n(^٣) أخرجه الإمام أحمد بسنده ومتنه، وصحح سنده محققوه. (المسند ١٦/ ٢٤٥ ح ١٠٣٧٩).\n(^٤) زيادة من (حم).","vol": "7","page": 647}
" is an HTML entity, (^١) to (^٤) are footnote markers, the square brackets are the editor’s, and the underscores part the text from four notes: two glosses, a reference for the hadith and a note on the bracketed word. The notes are the editor’s words, not Ibn Kathir’s. Elsewhere:
- Heading spans, such as
<span data-type="title" id="toc-1" data-level="1">around مقدمة الناشر, the first line of Ibn Kathir’s file. - Ayah anchors, numbered through the whole Qur’an:
<span id="aya-6180"> </span>is 104:1, where Ibn Kathir’s commentary on al-Humaza begins. - Footnote markers in four styles:
(^١),(١),[١]and«١». - Page markers such as
⦗٤٩٢⦘, and honorifics set as one character, such as ﷺ.
The decoder keeps all of it. The chunker cleans the setting, never the words, and that is harder than it sounds. A plain (١) can be a footnote marker or, inside a quote, an ayah’s number. Writing tests on real excerpts turned up mistakes both ways: «١» markers had been left in the text in about 25,000 places, and ayah numbers deleted as markers on pages with a note of the same number. Now (١) or [١] is a marker only on a page that has that note, and never inside a Qur’an quote. Honorifics stay in the passage, and the keyword copy drops them.
Pages that are not the author’s
Two fields say where the author’s text is: meta.author_page_start and indexes.non_author. We index only the author’s pages. They are the scholar speaking, and the editor’s are the part most likely to be under copyright. The decoder takes both fields: every listed page, and every page before the author’s first.
non_author is only reliable in newer files. Where a file marks nothing, the chunker starts at the author’s own introduction or the first surah. In every file it also leaves out sections under an editor’s heading, and treats index headings such as فهارس near the end of a book or a volume as back matter. Before a review fixed it, 1,513 passages sat under index headings; now none do. One case is done by hand: two pages of al-Qushayri’s tafsir, the editor’s signed afterword.
Copyright is wider than those pages. Of the 275 tafsirs, 84 are by authors who died in 1375 AH or later, and 73 have no death year. Footnotes are the editor’s words too, so they are stored and not served unless SERVE_NOTES is "1". Both points are ours to settle with Nuqayah.
Refuse the whole book
A book that does not look exactly as expected is refused whole. A half-read book is never indexed. An unknown layout, a scrambled name past the end of its list, a missing meta.id or meta.name, a field such as meta.printed present with the wrong type, and a heading that points past the last page are all refused. Each refusal is a TurathFormatError, like these from our tests:
turath: unknown layout; top-level names are U+64b, pages, U+670turath: unknown scrambled name U+661 in metaturath: meta.printed is missing or has the wrong type
The Worker that loads books logs format_error and does not retry. As the code says, “Trying again cannot help: a person has to look.” The raw file is already in R2, nothing has been written to the database, and the version loaded before stays as it was.
The U+0660 bug is the argument for this. The costly failures are the quiet ones: a list read as empty, an editor’s introduction indexed under a scholar’s name. A refusal costs a log line and a person’s attention. A half-read book costs the one thing the library promises: that the words under a scholar’s name are the scholar’s own.
turath’s format is unofficial and could change. When it does, we would rather hear it from an error than from a reader.