diff --git a/pyproject.toml b/pyproject.toml index 9e38f0c..674dec0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,7 +3,7 @@ requires = ["setuptools>=61.0"] build-backend = "setuptools.build_meta" [project] name = "json_repair" -version = "0.19.1" +version = "0.19.2" license = {file = "LICENSE"} authors = [ { name="Stefano Baccianella", email="4247706+mangiucugna@users.noreply.github.com" }, diff --git a/src/json_repair/json_repair.py b/src/json_repair/json_repair.py index 610847c..7f7c67f 100644 --- a/src/json_repair/json_repair.py +++ b/src/json_repair/json_repair.py @@ -249,7 +249,8 @@ def parse_string(self) -> str: rstring_delimiter = "”" elif char.isalpha(): # This could be a and not a string. Because (T)rue or (F)alse or (N)ull are valid - if char.lower() in ["t", "f", "n"]: + # But remember, object keys are only of type string + if char.lower() in ["t", "f", "n"] and self.get_context() != "object_key": value = self.parse_boolean_or_null() if value != "": return value diff --git a/tests/test_json_repair.py b/tests/test_json_repair.py index a7ed72a..203fd30 100644 --- a/tests/test_json_repair.py +++ b/tests/test_json_repair.py @@ -120,6 +120,7 @@ def test_object_edge_cases(): assert repair_json('{ "words": abcdef", "numbers": 12345", "words2": ghijkl" }') == '{"words": "abcdef", "numbers": 12345, "words2": "ghijkl"}' assert repair_json('''{"number": 1,"reason": "According...""ans": "YES"}''') == '{"number": 1, "reason": "According...", "ans": "YES"}' assert repair_json('''{ "a": "{ b": {} }" }''') == '{"a": "{ b"}' + assert repair_json("""{"b": "xxxxx" true}""") == '{"b": "xxxxx"}' def test_number_edge_cases(): assert repair_json(' - { "test_key": ["test_value", "test_value2"] }') == '{"test_key": ["test_value", "test_value2"]}'