A Python script that fetches JSON data from an API and converts it to SQL INSERT statements.
- Fetches JSON data from any API endpoint
 - Automatically generates CREATE TABLE statements
 - Converts JSON objects to SQL INSERT statements
 - Handles nested objects and arrays
 - Saves SQL file in the same directory
 - Automatically extracts table name from API endpoint
 
- Install the required dependencies:
 
pip install -r requirements.txtpython api_to_sql.py <API_URL>Example:
python api_to_sql.py https://jsonplaceholder.typicode.com/usersIf you run the script without arguments, it will prompt you for the API URL:
python api_to_sql.pyThe script generates a .sql file with:
- CREATE TABLE statement (auto-generated based on the JSON structure)
 - INSERT statements for all data items
 - Comments with metadata (timestamp, source API)
 
Example API endpoints you can try:
# Get users data
python api_to_sql.py https://jsonplaceholder.typicode.com/users
# Get posts data
python api_to_sql.py https://jsonplaceholder.typicode.com/posts
# Get todos
python api_to_sql.py https://jsonplaceholder.typicode.com/todos- The table name is automatically extracted from the API URL path
 - If multiple files would have the same name, numbered suffixes are added (e.g., 
users_1.sql) - Nested JSON objects and arrays are stored as TEXT (JSON strings)
 - The script handles various data types: strings, numbers, booleans, null values