Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# json2sql — Agent Guide

## Repo overview
This repo converts JSON to SQL. Primary implementation is under `src/json2sql/`. CLI entrypoints live in `cli.py` and `__main__.py`.

## Commands
- Install/dev: `pip install -e .`
- Tests: `pytest`
- Lint/type checks (if configured): use tooling in `pyproject.toml`

## Do not break
- Do not remove or weaken existing tests.
- Keep public CLI behavior stable unless an issue explicitly requests changing it.
4 changes: 1 addition & 3 deletions src/json2sql/cli.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""CLI interface for json2sql using Typer."""

import sys
from pathlib import Path

import typer
from pathlib import Path

# Lazy imports — converter/dialects pulled on command execution
# to reduce cold start from ~340ms to ~160ms.
Expand Down Expand Up @@ -64,8 +64,6 @@ def convert(
),
):
"""Convert a JSON file to SQL INSERT statements."""
from .converter import JSONToSQLConverter
from .dialects import Dialect

# Validate dialect
try:
Expand Down
6 changes: 3 additions & 3 deletions src/json2sql/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def _convert_objects(self, objects: list[dict], table_name: str) -> str:
# Process nested arrays into child tables
for obj in objects:
for key, value in obj.items():
if isinstance(value, list) and value and isinstance(value[0], dict):
if isinstance(value, list) and value and all(isinstance(v, dict) for v in value):
self._flatten_nested(table_name, key, value, obj)
else:
columns = self._infer_columns(objects)
Expand Down Expand Up @@ -163,7 +163,7 @@ def _infer_columns_flattened(
inferred = sql_type_for(sub_value, self.dialect)
if columns[flat_key] == "TEXT" and inferred != "TEXT":
columns[flat_key] = inferred
elif isinstance(value, list) and value and isinstance(value[0], dict) and self.flatten:
elif isinstance(value, list) and value and self.flatten and all(isinstance(v, dict) for v in value):
# Skip - goes to separate table
pass
else:
Expand Down Expand Up @@ -216,5 +216,5 @@ def _process_flatten(self, objects: list, table_name: str) -> None:
return
for obj in objects:
for key, value in obj.items():
if isinstance(value, list) and value and isinstance(value[0], dict):
if isinstance(value, list) and value and all(isinstance(v, dict) for v in value):
self._flatten_nested(table_name, key, value, obj)