Convert Bible JSON to SQLite Database

JSON Files:

https://github.com/aruljohn/Bible-kjv

Python Script:

import json
import sqlite3

conn = sqlite3.connect('sword.db')
c = conn.cursor()

bookNames = ["Genesis", "Exodus", "Leviticus", "Numbers", "Deuteronomy", "Joshua", "Judges", "Ruth", "1Samuel", "2Samuel", "1Kings", "2Kings", "1Chronicles", "2Chronicles", "Ezra", "Nehemiah", "Esther", "Job", "Psalms", "Proverbs", "Ecclesiastes", "SongofSolomon", "Isaiah", "Jeremiah", "Lamentations", "Ezekiel", "Daniel", "Hosea", "Joel", "Amos", "Obadiah", "Jonah", "Micah", "Nahum", "Habakkuk", "Zephaniah", "Haggai", "Zechariah", "Malachi", "Matthew", "Mark", "Luke", "John", "Acts", "Romans", "1Corinthians", "2Corinthians", "Galatians", "Ephesians", "Philippians", "Colossians", "1Thessalonians", "2Thessalonians", "1Timothy", "2Timothy", "Titus", "Philemon", "Hebrews", "James", "1Peter", "2Peter", "1John", "2John", "3John", "Jude", "Revelation"]

count=0
B_KEY_BOOK_NAME = "book_name";
B_KEY_CHAP_NUM = "chapter_num";
B_KEY_VERSE_NUM = "verse_num";
B_KEY_VERSE_TEXT = "verse_text";

c.execute("CREATE TABLE " + "bible" + "("
+ B_KEY_BOOK_NAME + " TEXT, "
+ B_KEY_CHAP_NUM + " INTEGER, "
+ B_KEY_VERSE_NUM + " INTEGER, "
+ B_KEY_VERSE_TEXT + " TEXT" + ")")

C_KEY_ID = "id";
C_KEY_SEQ = "seq";
C_KEY_BOOK_NAME = "book_name";
C_KEY_CHAP_NUM = "chapter_num";
C_KEY_START_VERSE_NUM = "start_verse_num";
C_KEY_END_VERSE_NUM = "end_verse_num";
C_KEY_NEXT_DATE_OF_REVIEW = "next_date_of_review";
C_KEY_SPACE = "space";
C_KEY_SEC_ID = "sec_id";

c.execute("CREATE TABLE " + "chunk" + "("
+ C_KEY_ID + " INTEGER PRIMARY KEY, "
+ C_KEY_SEQ + " INTEGER, "
+ C_KEY_BOOK_NAME + " TEXT, "
+ C_KEY_CHAP_NUM + " INTEGER, "
+ C_KEY_START_VERSE_NUM + " INTEGER, "
+ C_KEY_END_VERSE_NUM + " INTEGER, "
+ C_KEY_NEXT_DATE_OF_REVIEW + " TEXT, "
+ C_KEY_SPACE + " INTEGER, "
+ C_KEY_SEC_ID + " INTEGER" + ")")

for i in range(66):
 with open('JSON/' + bookNames[i] + '.json') as data_file:
  data = json.load(data_file)
 nChap = len(data["chapters"])
 print(nChap)
 for j in range(nChap):
  nVerse = len(data["chapters"][j]["verses"])
  for k in range(nVerse):
   c.execute("INSERT INTO bible VALUES(" + "'" + data["book"] + "'" + "," + data["chapters"][j]["chapter"] + "," + str(k+1) + "," + "'" + data["chapters"][j]["verses"][k][str(k+1)] + "'" + ")")
  print(bookNames[i] + " Done")
  conn.commit()
conn.close()

Browse Database:

SQLiteOnline – https://sqliteonline.com/

Steps:

  1. Download all the 66 JSON files from the GitHub repository.
  2. Store these files in a folder named JSON, and store this JSON folder in another folder(say my project) where you want to put your python script.
  3. Now save the python script in the folder my project, and run it.
  4. Once done, you will find the file example.db in the my project folder.
  5. You can browse this database file by using the SQLiteOnline browser.

One thought on “Convert Bible JSON to SQLite Database

  1. Brad Thorby says:

    Good morning, I was just taking a look at your site and filled out your feedback form. The “contact us” page on your site sends you messages like this via email which is the reason you are reading my message at this moment right? This is half the battle with any kind of advertising, making people actually READ your advertisement and I did that just now with you! If you have an ad message you would like to blast out to lots of websites via their contact forms in the U.S. or to any country worldwide let me know, I can even target particular niches and my charges are very affordable. Reply here: Phungcorsi@gmail.com

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.