Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Studio: show a JSON seed's values as written in the Data Recipe preview (#12180)

Mohammad Hijjawibdd3b002b35f
diff --git a/studio/backend/routes/data_recipe/seed.py b/studio/backend/routes/data_recipe/seed.py
index 3352dee9bc1..8d44c2a0f94 100644
--- a/studio/backend/routes/data_recipe/seed.py
+++ b/studio/backend/routes/data_recipe/seed.py
@@ -974,6 +974,10 @@ def _decode_base64_payload(content_base64: str) -> bytes:
raise HTTPException(status_code = 400, detail = "invalid base64 payload") from exc
+# Match the recipe's DuckDB read: inference made "007" -> 7 and a created_at number a date.
+_JSON_READ_OPTIONS = {"dtype": False, "convert_dates": False}
+
+
def _read_preview_rows_from_local_file(path: Path, preview_size: int) -> list[dict[str, Any]]:
account_path(path)
try:
@@ -1009,12 +1013,12 @@ def _read_preview_rows_from_local_file(path: Path, preview_size: int) -> list[di
full_df.to_csv(tmp_csv, index = False, encoding = "utf-8")
tmp_csv.replace(path)
elif ext == ".jsonl":
- df = pd.read_json(path, lines = True).head(preview_size)
+ df = pd.read_json(path, lines = True, **_JSON_READ_OPTIONS).head(preview_size)
elif ext == ".json":
try:
- df = pd.read_json(path).head(preview_size)
+ df = pd.read_json(path, **_JSON_READ_OPTIONS).head(preview_size)
except ValueError:
- df = pd.read_json(path, lines = True).head(preview_size)
+ df = pd.read_json(path, lines = True, **_JSON_READ_OPTIONS).head(preview_size)
else:
raise HTTPException(status_code = 422, detail = f"unsupported file type: {ext}")
except HTTPException:
diff --git a/studio/backend/tests/test_data_recipe_seed.py b/studio/backend/tests/test_data_recipe_seed.py
index 024659a6bc7..b2a72754f90 100644
--- a/studio/backend/tests/test_data_recipe_seed.py
+++ b/studio/backend/tests/test_data_recipe_seed.py
@@ -5,6 +5,7 @@ import asyncio
import base64
import importlib.util
import io
+import json
import sys
from pathlib import Path
from types import SimpleNamespace
@@ -104,6 +105,25 @@ def test_local_csv_seed_keeps_its_values_as_written(monkeypatch, tmp_path):
]
[email protected]("filename", ["seed.jsonl", "seed.json"])
+def test_local_json_seed_preview_keeps_its_values_as_written(monkeypatch, tmp_path, filename):
+ seed_route = _load_seed_route(monkeypatch, tmp_path)
+ monkeypatch.setattr(seed_route, "account_path", lambda path: None)
+ records = [
+ {"zip": "01234", "qty": 3, "created_at": 1700000000, "date": "2024-01-01"},
+ {"zip": "90210", "qty": 4, "created_at": 1700000001, "date": "2024-01-02"},
+ ]
+ path = tmp_path / filename
+ if filename.endswith(".jsonl"):
+ path.write_text("\n".join(json.dumps(record) for record in records), encoding = "utf-8")
+ else:
+ path.write_text(json.dumps(records), encoding = "utf-8")
+
+ rows = seed_route._read_preview_rows_from_local_file(path, 10)
+
+ assert rows == records
+
+
@pytest.mark.parametrize(
("filename", "module", "package"),
[