From 03f1cd30739d5352677ed8c0dce7ba837648648d Mon Sep 17 00:00:00 2001 From: Chaimaa Abi <118536453+Cha-Imaa@users.noreply.github.com> Date: Sun, 27 Sep 2026 15:36:39 +0400 Subject: [PATCH 1/4] fix: handle scalar content values in JSONConverter --- haystack/components/converters/json.py | 3 +++ test/components/converters/test_json.py | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/haystack/components/converters/json.py b/haystack/components/converters/json.py index 9510ed9fcb8..300826b196c 100644 --- a/haystack/components/converters/json.py +++ b/haystack/components/converters/json.py @@ -238,6 +238,9 @@ def _get_content_and_meta(self, source: ByteStream) -> list[tuple[str, dict[str, logger.warning("Expected a scalar value but got {obj}. Skipping it.", obj=obj) continue + if text is not None and not isinstance(text, str): + text = str(text) + meta = {} if meta_fields == "*": meta = {k: v for k, v in obj.items() if k != self._content_key} diff --git a/test/components/converters/test_json.py b/test/components/converters/test_json.py index 59fee4875be..83d77dd26cc 100644 --- a/test/components/converters/test_json.py +++ b/test/components/converters/test_json.py @@ -511,6 +511,16 @@ def test_run_with_content_key(tmpdir): assert result["documents"][2].meta == {} +@pytest.mark.parametrize("value, expected", [(123, "123"), (True, "True")]) +def test_run_with_content_key_with_scalar_values(value, expected): + source = ByteStream.from_string(json.dumps({"body": value})) + + converter = JSONConverter(content_key="body") + result = converter.run(sources=[source]) + + assert result["documents"][0].content == expected + + def test_run_with_content_key_and_extra_meta_fields(tmpdir): first_test_file = Path(tmpdir / "first_test_file.json") second_test_file = Path(tmpdir / "second_test_file.json") From 053f01cdff443d1ca46e48bdaff79a7c918e4a9e Mon Sep 17 00:00:00 2001 From: Chaimaa Abi <118536453+Cha-Imaa@users.noreply.github.com> Date: Mon, 28 Sep 2026 13:27:34 +0400 Subject: [PATCH 2/4] test: cover float and null JSON content values --- test/components/converters/test_json.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/test/components/converters/test_json.py b/test/components/converters/test_json.py index 83d77dd26cc..8168051c8b9 100644 --- a/test/components/converters/test_json.py +++ b/test/components/converters/test_json.py @@ -511,7 +511,15 @@ def test_run_with_content_key(tmpdir): assert result["documents"][2].meta == {} -@pytest.mark.parametrize("value, expected", [(123, "123"), (True, "True")]) +@pytest.mark.parametrize( + "value, expected", + [ + (123, "123"), + (1.5, "1.5"), + (True, "True"), + (None, None), + ], +) def test_run_with_content_key_with_scalar_values(value, expected): source = ByteStream.from_string(json.dumps({"body": value})) From a18f8ec39eb4ed7c5d4d34172763e881044482c3 Mon Sep 17 00:00:00 2001 From: Chaimaa Abi <118536453+Cha-Imaa@users.noreply.github.com> Date: Mon, 28 Sep 2026 13:47:23 +0400 Subject: [PATCH 3/4] docs: add release note for JSONConverter scalar content --- .../json-converter-scalar-content-163133a47060a2e7.yaml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 releasenotes/notes/json-converter-scalar-content-163133a47060a2e7.yaml diff --git a/releasenotes/notes/json-converter-scalar-content-163133a47060a2e7.yaml b/releasenotes/notes/json-converter-scalar-content-163133a47060a2e7.yaml new file mode 100644 index 00000000000..eaf729f667f --- /dev/null +++ b/releasenotes/notes/json-converter-scalar-content-163133a47060a2e7.yaml @@ -0,0 +1,5 @@ +--- +fixes: + - | + Fixed ``JSONConverter`` failing with ``ValueError`` when ``content_key`` contains numeric or boolean scalar values. + These values are now converted to strings before creating the ``Document``, while ``null`` values remain unchanged. From f4e06f4a11bcff62e5cecad1997109060a9f7f8f Mon Sep 17 00:00:00 2001 From: Chaimaa Abi <118536453+Cha-Imaa@users.noreply.github.com> Date: Mon, 28 Sep 2026 14:37:07 +0400 Subject: [PATCH 4/4] style: format scalar content regression test --- test/components/converters/test_json.py | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/test/components/converters/test_json.py b/test/components/converters/test_json.py index 8168051c8b9..c3b5d37f480 100644 --- a/test/components/converters/test_json.py +++ b/test/components/converters/test_json.py @@ -511,15 +511,7 @@ def test_run_with_content_key(tmpdir): assert result["documents"][2].meta == {} -@pytest.mark.parametrize( - "value, expected", - [ - (123, "123"), - (1.5, "1.5"), - (True, "True"), - (None, None), - ], -) +@pytest.mark.parametrize("value, expected", [(123, "123"), (1.5, "1.5"), (True, "True"), (None, None)]) def test_run_with_content_key_with_scalar_values(value, expected): source = ByteStream.from_string(json.dumps({"body": value}))