Skip to content

Instantly share code, notes, and snippets.

@Patrick-web
Created September 26, 2021 02:18
Show Gist options
  • Save Patrick-web/22a808be5f8c65588fb7ff7110cf190c to your computer and use it in GitHub Desktop.
Save Patrick-web/22a808be5f8c65588fb7ff7110cf190c to your computer and use it in GitHub Desktop.
JSON Bible Parser
const path = require("path");
const fs = require("fs");
function parseBible(biblePath) {
console.time("parsing time");
const files = fs.readdirSync(biblePath);
files.filter((file) => file == "books.json");
const bookNames = JSON.parse(
fs.readFileSync(path.join(biblePath, "books.json"))
).bookNames;
let books = [];
for (let index = 0; index < 65; index++) {
const book = {
name: bookNames[index],
chapters: [],
};
files.forEach((file) => {
if (file.startsWith(`${index}-`)) {
book.chapters.push(file);
}
});
book.chapters = book.chapters.map((value, chapIndex) => {
const chap = `${index}-${chapIndex}.json`;
const verses = JSON.parse(
fs.readFileSync(path.join(biblePath, chap))
).verses;
const newChapter = new Map();
newChapter.set(chap, verses);
return newChapter;
});
books.push(book);
}
console.log(books);
console.timeEnd("parsing time");
}
parseBible("./KJV");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment