diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..e2523e5 --- /dev/null +++ b/AGENTS.md @@ -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. diff --git a/src/json2sql/cli.py b/src/json2sql/cli.py index 3cf4753..7d145e3 100644 --- a/src/json2sql/cli.py +++ b/src/json2sql/cli.py @@ -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. @@ -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: diff --git a/src/json2sql/converter.py b/src/json2sql/converter.py index f6b7cb8..deb0b0e 100644 --- a/src/json2sql/converter.py +++ b/src/json2sql/converter.py @@ -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) @@ -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: @@ -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)