Skip to content

Commit 5500015

Browse files
improve: add AGENTS.md and harden flatten list typing (#28)
* improve: add AGENTS.md and harden flatten list typing * fix: harden list-of-dict type checks in flatten paths by reviewer-B * style: auto-fix ruff import sorting (I001)
1 parent 1600ea4 commit 5500015

3 files changed

Lines changed: 17 additions & 6 deletions

File tree

AGENTS.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# json2sql — Agent Guide
2+
3+
## Repo overview
4+
This repo converts JSON to SQL. Primary implementation is under `src/json2sql/`. CLI entrypoints live in `cli.py` and `__main__.py`.
5+
6+
## Commands
7+
- Install/dev: `pip install -e .`
8+
- Tests: `pytest`
9+
- Lint/type checks (if configured): use tooling in `pyproject.toml`
10+
11+
## Do not break
12+
- Do not remove or weaken existing tests.
13+
- Keep public CLI behavior stable unless an issue explicitly requests changing it.

src/json2sql/cli.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
"""CLI interface for json2sql using Typer."""
22

33
import sys
4+
from pathlib import Path
45

56
import typer
6-
from pathlib import Path
77

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

7068
# Validate dialect
7169
try:

src/json2sql/converter.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def _convert_objects(self, objects: list[dict], table_name: str) -> str:
8484
# Process nested arrays into child tables
8585
for obj in objects:
8686
for key, value in obj.items():
87-
if isinstance(value, list) and value and isinstance(value[0], dict):
87+
if isinstance(value, list) and value and all(isinstance(v, dict) for v in value):
8888
self._flatten_nested(table_name, key, value, obj)
8989
else:
9090
columns = self._infer_columns(objects)
@@ -163,7 +163,7 @@ def _infer_columns_flattened(
163163
inferred = sql_type_for(sub_value, self.dialect)
164164
if columns[flat_key] == "TEXT" and inferred != "TEXT":
165165
columns[flat_key] = inferred
166-
elif isinstance(value, list) and value and isinstance(value[0], dict) and self.flatten:
166+
elif isinstance(value, list) and value and self.flatten and all(isinstance(v, dict) for v in value):
167167
# Skip - goes to separate table
168168
pass
169169
else:
@@ -216,5 +216,5 @@ def _process_flatten(self, objects: list, table_name: str) -> None:
216216
return
217217
for obj in objects:
218218
for key, value in obj.items():
219-
if isinstance(value, list) and value and isinstance(value[0], dict):
219+
if isinstance(value, list) and value and all(isinstance(v, dict) for v in value):
220220
self._flatten_nested(table_name, key, value, obj)

0 commit comments

Comments
 (0)