JSON importieren
Ausgangssituation
Ich habe eine JSON-Datei mit Namen. Diese möchte ich in eine SQLite-Datenbank importieren. Die JSON-Datei sieht so aus:
[
  {
    "name": "Aaron",
    "gender": "male",
    "country": "gb"
  },
  {
    "name": "Aarron",
    "gender": "male",
    "country": "gb"
  }
]Tabelle anlegen
 CREATE TABLE names (name TEXT, gender TEXT, country TEXT);JSON importieren
INSERT INTO names SELECT 
  json_extract(value, '$.name'), 
  json_extract(value, '$.gender'),
  json_extract(value, '$.country')
FROM json_each(readfile('names.json'));Index erzeugen
Abschließend lässt sich noch ein Index auf die Namensspalte legen:
 CREATE INDEX idx_names_name ON names(name);
https://stackoverflow.com/questions/46407770/how-to-convert-a-json-file-to-an-sqlite-database
 
                
No Comments