json-repair 0.54__tar.gz → 0.54.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {json_repair-0.54/src/json_repair.egg-info → json_repair-0.54.2}/PKG-INFO +1 -1
- {json_repair-0.54 → json_repair-0.54.2}/pyproject.toml +1 -1
- {json_repair-0.54 → json_repair-0.54.2}/src/json_repair/json_parser.py +4 -1
- {json_repair-0.54 → json_repair-0.54.2}/src/json_repair/parse_number.py +3 -2
- {json_repair-0.54 → json_repair-0.54.2/src/json_repair.egg-info}/PKG-INFO +1 -1
- {json_repair-0.54 → json_repair-0.54.2}/tests/test_json_repair.py +2 -2
- {json_repair-0.54 → json_repair-0.54.2}/tests/test_parse_number.py +2 -0
- {json_repair-0.54 → json_repair-0.54.2}/tests/test_parse_object.py +2 -2
- {json_repair-0.54 → json_repair-0.54.2}/tests/test_strict_mode.py +1 -1
- {json_repair-0.54 → json_repair-0.54.2}/LICENSE +0 -0
- {json_repair-0.54 → json_repair-0.54.2}/README.md +0 -0
- {json_repair-0.54 → json_repair-0.54.2}/setup.cfg +0 -0
- {json_repair-0.54 → json_repair-0.54.2}/src/json_repair/__init__.py +0 -0
- {json_repair-0.54 → json_repair-0.54.2}/src/json_repair/__main__.py +0 -0
- {json_repair-0.54 → json_repair-0.54.2}/src/json_repair/json_repair.py +0 -0
- {json_repair-0.54 → json_repair-0.54.2}/src/json_repair/parse_array.py +0 -0
- {json_repair-0.54 → json_repair-0.54.2}/src/json_repair/parse_comment.py +0 -0
- {json_repair-0.54 → json_repair-0.54.2}/src/json_repair/parse_object.py +0 -0
- {json_repair-0.54 → json_repair-0.54.2}/src/json_repair/parse_string.py +0 -0
- {json_repair-0.54 → json_repair-0.54.2}/src/json_repair/parse_string_helpers/parse_boolean_or_null.py +0 -0
- {json_repair-0.54 → json_repair-0.54.2}/src/json_repair/parse_string_helpers/parse_json_llm_block.py +0 -0
- {json_repair-0.54 → json_repair-0.54.2}/src/json_repair/py.typed +0 -0
- {json_repair-0.54 → json_repair-0.54.2}/src/json_repair/utils/constants.py +0 -0
- {json_repair-0.54 → json_repair-0.54.2}/src/json_repair/utils/json_context.py +0 -0
- {json_repair-0.54 → json_repair-0.54.2}/src/json_repair/utils/object_comparer.py +0 -0
- {json_repair-0.54 → json_repair-0.54.2}/src/json_repair/utils/string_file_wrapper.py +0 -0
- {json_repair-0.54 → json_repair-0.54.2}/src/json_repair.egg-info/SOURCES.txt +0 -0
- {json_repair-0.54 → json_repair-0.54.2}/src/json_repair.egg-info/dependency_links.txt +0 -0
- {json_repair-0.54 → json_repair-0.54.2}/src/json_repair.egg-info/entry_points.txt +0 -0
- {json_repair-0.54 → json_repair-0.54.2}/src/json_repair.egg-info/top_level.txt +0 -0
- {json_repair-0.54 → json_repair-0.54.2}/tests/test_parse_array.py +0 -0
- {json_repair-0.54 → json_repair-0.54.2}/tests/test_parse_comment.py +0 -0
- {json_repair-0.54 → json_repair-0.54.2}/tests/test_parse_string.py +0 -0
- {json_repair-0.54 → json_repair-0.54.2}/tests/test_performance.py +0 -0
- {json_repair-0.54 → json_repair-0.54.2}/tests/test_repair_json_cli.py +0 -0
- {json_repair-0.54 → json_repair-0.54.2}/tests/test_repair_json_from_file.py +0 -0
|
@@ -84,10 +84,13 @@ class JSONParser:
|
|
|
84
84
|
while self.index < len(self.json_str):
|
|
85
85
|
self.context.reset()
|
|
86
86
|
j = self.parse_json()
|
|
87
|
-
if j
|
|
87
|
+
if j:
|
|
88
88
|
if ObjectComparer.is_same_object(json[-1], j):
|
|
89
89
|
# replace the last entry with the new one since the new one seems an update
|
|
90
90
|
json.pop()
|
|
91
|
+
else:
|
|
92
|
+
if not json[-1]:
|
|
93
|
+
json.pop()
|
|
91
94
|
json.append(j)
|
|
92
95
|
else:
|
|
93
96
|
# this was a bust, move the index
|
|
@@ -3,7 +3,7 @@ from typing import TYPE_CHECKING
|
|
|
3
3
|
from .utils.constants import JSONReturnType
|
|
4
4
|
from .utils.json_context import ContextValues
|
|
5
5
|
|
|
6
|
-
NUMBER_CHARS: set[str] = set("0123456789-.eE/,")
|
|
6
|
+
NUMBER_CHARS: set[str] = set("0123456789-.eE/,_")
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
if TYPE_CHECKING:
|
|
@@ -16,7 +16,8 @@ def parse_number(self: "JSONParser") -> JSONReturnType:
|
|
|
16
16
|
char = self.get_char_at()
|
|
17
17
|
is_array = self.context.current == ContextValues.ARRAY
|
|
18
18
|
while char and char in NUMBER_CHARS and (not is_array or char != ","):
|
|
19
|
-
|
|
19
|
+
if char != "_":
|
|
20
|
+
number_str += char
|
|
20
21
|
self.index += 1
|
|
21
22
|
char = self.get_char_at()
|
|
22
23
|
if number_str and number_str[-1] in "-eE/,":
|
|
@@ -18,8 +18,8 @@ def test_valid_json():
|
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
def test_multiple_jsons():
|
|
21
|
-
assert repair_json("[]{}") == "[
|
|
22
|
-
assert repair_json(
|
|
21
|
+
assert repair_json("[]{}") == "[]"
|
|
22
|
+
assert repair_json('[]{"key":"value"}') == '{"key": "value"}'
|
|
23
23
|
assert repair_json('{"key":"value"}[1,2,3,True]') == '[{"key": "value"}, [1, 2, 3, true]]'
|
|
24
24
|
assert (
|
|
25
25
|
repair_json('lorem ```json {"key":"value"} ``` ipsum ```json [1,2,3,True] ``` 42')
|
|
@@ -4,6 +4,8 @@ from src.json_repair.json_repair import repair_json
|
|
|
4
4
|
def test_parse_number():
|
|
5
5
|
assert repair_json("1", return_objects=True) == 1
|
|
6
6
|
assert repair_json("1.2", return_objects=True) == 1.2
|
|
7
|
+
assert repair_json('{"value": 82_461_110}', return_objects=True) == {"value": 82461110}
|
|
8
|
+
assert repair_json('{"value": 1_234.5_6}', return_objects=True) == {"value": 1234.56}
|
|
7
9
|
|
|
8
10
|
|
|
9
11
|
def test_parse_number_edge_cases():
|
|
@@ -89,9 +89,9 @@ def test_parse_object_edge_cases():
|
|
|
89
89
|
def test_parse_object_merge_at_the_end():
|
|
90
90
|
assert repair_json('{"key": "value"}, "key2": "value2"}') == '{"key": "value", "key2": "value2"}'
|
|
91
91
|
assert repair_json('{"key": "value"}, "key2": }') == '{"key": "value", "key2": ""}'
|
|
92
|
-
assert repair_json('{"key": "value"}, []') == '
|
|
92
|
+
assert repair_json('{"key": "value"}, []') == '{"key": "value"}'
|
|
93
93
|
assert repair_json('{"key": "value"}, ["abc"]') == '[{"key": "value"}, ["abc"]]'
|
|
94
|
-
assert repair_json('{"key": "value"}, {}') == '
|
|
94
|
+
assert repair_json('{"key": "value"}, {}') == '{"key": "value"}'
|
|
95
95
|
assert repair_json('{"key": "value"}, "" : "value2"}') == '{"key": "value", "": "value2"}'
|
|
96
96
|
assert repair_json('{"key": "value"}, "key2" "value2"}') == '{"key": "value", "key2": "value2"}'
|
|
97
97
|
assert (
|
|
@@ -5,7 +5,7 @@ from src.json_repair.json_repair import repair_json
|
|
|
5
5
|
|
|
6
6
|
def test_strict_rejects_multiple_top_level_values():
|
|
7
7
|
with pytest.raises(ValueError, match="Multiple top-level JSON elements"):
|
|
8
|
-
repair_json("
|
|
8
|
+
repair_json('{"key":"value"}["value"]', strict=True)
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
def test_strict_duplicate_keys_inside_array():
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{json_repair-0.54 → json_repair-0.54.2}/src/json_repair/parse_string_helpers/parse_json_llm_block.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|