From d7b47ae326ca0e10f004d759dd3cbe5123bde309 Mon Sep 17 00:00:00 2001 From: Adam Fourney Date: Fri, 3 Jan 2025 16:30:44 -0800 Subject: [PATCH 1/2] Recognize json as plain text (if no other handlers are present). --- src/markitdown/_markitdown.py | 5 ++++- tests/test_markitdown.py | 9 +++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/markitdown/_markitdown.py b/src/markitdown/_markitdown.py index aceaa86..b6acfe8 100644 --- a/src/markitdown/_markitdown.py +++ b/src/markitdown/_markitdown.py @@ -173,7 +173,10 @@ def convert( # Only accept text files if content_type is None: return None - elif "text/" not in content_type.lower(): + elif all( + not content_type.lower().startswith(type_prefix) + for type_prefix in ["text/", "application/json"] + ): return None text_content = str(from_path(local_path).best()) diff --git a/tests/test_markitdown.py b/tests/test_markitdown.py index e2d2e75..3333bcb 100644 --- a/tests/test_markitdown.py +++ b/tests/test_markitdown.py @@ -145,6 +145,11 @@ "5bda1dd6", ] +JSON_TEST_STRINGS = [ + "5b64c88c-b3c3-4510-bcb8-da0b200602d8", + "9700dc99-6685-40b4-9a3a-5e406dcb37f3", +] + # --- Helper Functions --- def validate_strings(result, expected_strings, exclude_strings=None): @@ -257,6 +262,10 @@ def test_markitdown_local() -> None: result = markitdown.convert(os.path.join(TEST_FILES_DIR, "test_outlook_msg.msg")) validate_strings(result, MSG_TEST_STRINGS) + # Test JSON processing + result = markitdown.convert(os.path.join(TEST_FILES_DIR, "test.json")) + validate_strings(result, JSON_TEST_STRINGS) + # Test input with leading blank characters input_data = b" \n\n\n

Test

" result = markitdown.convert_stream(io.BytesIO(input_data)) From 18667a86f7148667cbd4d67649d9501ee72b3d52 Mon Sep 17 00:00:00 2001 From: Adam Fourney Date: Fri, 3 Jan 2025 16:38:34 -0800 Subject: [PATCH 2/2] Forgot the test file! --- tests/test_files/test.json | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 tests/test_files/test.json diff --git a/tests/test_files/test.json b/tests/test_files/test.json new file mode 100644 index 0000000..eba3059 --- /dev/null +++ b/tests/test_files/test.json @@ -0,0 +1,10 @@ +{ + "key1": "string_value", + "key2": 1234, + "key3": [ + "list_value1", + "list_value2" + ], + "5b64c88c-b3c3-4510-bcb8-da0b200602d8": "uuid_key", + "uuid_value": "9700dc99-6685-40b4-9a3a-5e406dcb37f3" +}