DEV Community

abhishekjaindba
abhishekjaindba

Posted on

Insert JSON Data File into PostgreSQL using Python Script

the psycopg2 library to connect to the database and execute an INSERT statement. Here is an example:

import json
import psycopg2

read JSON data from file

with open('data.json') as f:
data = json.load(f)

connect to the database

conn = psycopg2.connect(host="localhost", database="mydb", user="user", password="pass")

create a cursor

cur = conn.cursor()

Read full blog post:
https://thedbadmin.com/insert-json-data-file-into-postgresql-using-python-script/

Top comments (0)