DocsGPT icon indicating copy to clipboard operation
DocsGPT copied to clipboard

JSON parser splits scalar strings into characters and crashes on other scalar values

Open Ritwik-Mallavarapu opened this issue 1 month ago • 2 comments

Description

On main commit 73d03c4d4d3cd2b0267e4f345a33431ee9ba0aca, JSONParser.parse_file handles top-level objects and arrays but treats a top-level JSON string as an iterable of characters. Other valid scalar JSON values raise TypeError. A string document therefore gets newline characters inserted between every character, and numeric/boolean/null documents cannot be parsed.

Reproduction

Reproduced on Windows with Python 3.12 by importing the checked-in parser directly (no mocks, API keys, database, or running server). This is a parser-level reproduction, not a full ingestion UI test.

import json
import tempfile
from pathlib import Path
from docsgpt.parser.file.json_parser import JSONParser

with tempfile.TemporaryDirectory() as directory:
    path = Path(directory) / "scalar.json"
    for value in ["hello", 42, True, None, {"name": "hello"}, ["hello"]]:
        path.write_text(json.dumps(value), encoding="utf-8")
        try:
            print(repr(value), "=>", repr(JSONParser().parse_file(path)))
        except Exception as error:
            print(repr(value), "=>", type(error).__name__, str(error))

Actual output:

'hello' => 'h\\ne\\nl\\nl\\no'
42 => TypeError: 'int' object is not iterable
True => TypeError: 'bool' object is not iterable
None => TypeError: 'NoneType' object is not iterable
{'name': 'hello'} => "{'name': 'hello'}"
['hello'] => 'hello'

Proposed scope

Treat a top-level scalar as one row rather than iterating it. Preserve existing object/array behavior and the custom row separator and json_config options. Add regression tests covering strings, numbers, booleans and null in both concatenation modes, including empty strings. If scalar documents are intentionally unsupported, reject them explicitly instead of silently corrupting string content.

I searched existing issues and PR titles/content for JSONParser, JSON parser and scalar JSON without finding this report. I would like to work on this for Hacktoberfest; could you confirm the desired scalar representation and assign it to me before I prepare the PR? I am using AI assistance and will report actual validation results.

Ritwik-Mallavarapu avatar Oct 14 '26 10:10 Ritwik-Mallavarapu

Assigned to @Ritwik-Mallavarapu.

  • Please open a PR or post progress within 14 days; otherwise the issue may be released for others.
  • Read CONTRIBUTING.md and add regression tests under tests/ for both concatenation modes.
  • Include a screenshot or short recording showing the result in your PR.

The intended scalar representation still needs a maintainer's confirmation.

Automated triage. A maintainer will follow up.

arc53-machine avatar Oct 14 '26 10:10 arc53-machine

Progress: a focused local fix and regression tests are prepared. Proposed behavior is to normalize any non-array top-level value to one row: concatenation keeps existing str(item) formatting (True / None), and non-concatenated output preserves the decoded value in a one-element list. Object/array behavior and custom decoding are covered.

Python 3.12 validation: 19 failing cases before the fix; all 31 JSON parser tests pass afterward. Repository-wide Ruff and git diff --check pass. Focused tests used --noconftest with default addopts disabled because the normal harness requires missing PostgreSQL test dependencies. Full suite and full ingestion UI verification have not been run.

Scalar representation remains a proposal pending maintainer confirmation. Required visual evidence is pending before opening the PR. AI assistance was used to prepare and test the change.

Ritwik-Mallavarapu avatar Oct 14 '26 10:10 Ritwik-Mallavarapu