json-repair 0.45.1__tar.gz → 0.46.1__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.45.1/src/json_repair.egg-info → json_repair-0.46.1}/PKG-INFO +3 -2
- {json_repair-0.45.1 → json_repair-0.46.1}/README.md +2 -1
- {json_repair-0.45.1 → json_repair-0.46.1}/pyproject.toml +3 -3
- {json_repair-0.45.1 → json_repair-0.46.1}/src/json_repair/json_parser.py +18 -2
- {json_repair-0.45.1 → json_repair-0.46.1}/src/json_repair/object_comparer.py +1 -1
- {json_repair-0.45.1 → json_repair-0.46.1/src/json_repair.egg-info}/PKG-INFO +3 -2
- {json_repair-0.45.1 → json_repair-0.46.1}/tests/test_json_repair.py +1 -0
- {json_repair-0.45.1 → json_repair-0.46.1}/tests/test_performance.py +6 -6
- {json_repair-0.45.1 → json_repair-0.46.1}/LICENSE +0 -0
- {json_repair-0.45.1 → json_repair-0.46.1}/setup.cfg +0 -0
- {json_repair-0.45.1 → json_repair-0.46.1}/src/json_repair/__init__.py +0 -0
- {json_repair-0.45.1 → json_repair-0.46.1}/src/json_repair/__main__.py +0 -0
- {json_repair-0.45.1 → json_repair-0.46.1}/src/json_repair/json_context.py +0 -0
- {json_repair-0.45.1 → json_repair-0.46.1}/src/json_repair/json_repair.py +0 -0
- {json_repair-0.45.1 → json_repair-0.46.1}/src/json_repair/py.typed +0 -0
- {json_repair-0.45.1 → json_repair-0.46.1}/src/json_repair/string_file_wrapper.py +0 -0
- {json_repair-0.45.1 → json_repair-0.46.1}/src/json_repair.egg-info/SOURCES.txt +0 -0
- {json_repair-0.45.1 → json_repair-0.46.1}/src/json_repair.egg-info/dependency_links.txt +0 -0
- {json_repair-0.45.1 → json_repair-0.46.1}/src/json_repair.egg-info/entry_points.txt +0 -0
- {json_repair-0.45.1 → json_repair-0.46.1}/src/json_repair.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: json_repair
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.46.1
|
4
4
|
Summary: A package to repair broken json strings
|
5
5
|
Author-email: Stefano Baccianella <4247706+mangiucugna@users.noreply.github.com>
|
6
6
|
License: MIT License
|
@@ -38,7 +38,7 @@ License-File: LICENSE
|
|
38
38
|
Dynamic: license-file
|
39
39
|
|
40
40
|
[](https://pypi.org/project/json-repair/)
|
41
|
-

|
42
42
|
[](https://pypi.org/project/json-repair/)
|
43
43
|
[](https://github.com/sponsors/mangiucugna)
|
44
44
|
[](https://github.com/mangiucugna/json_repair/stargazers)
|
@@ -289,6 +289,7 @@ You will need owner access to this repository
|
|
289
289
|
- Typescript: https://github.com/josdejong/jsonrepair
|
290
290
|
- Go: https://github.com/RealAlexandreAI/json-repair
|
291
291
|
- Ruby: https://github.com/sashazykov/json-repair-rb
|
292
|
+
- Rust: https://github.com/oramasearch/llm_json
|
292
293
|
---
|
293
294
|
## Star History
|
294
295
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
[](https://pypi.org/project/json-repair/)
|
2
|
-

|
3
3
|
[](https://pypi.org/project/json-repair/)
|
4
4
|
[](https://github.com/sponsors/mangiucugna)
|
5
5
|
[](https://github.com/mangiucugna/json_repair/stargazers)
|
@@ -250,6 +250,7 @@ You will need owner access to this repository
|
|
250
250
|
- Typescript: https://github.com/josdejong/jsonrepair
|
251
251
|
- Go: https://github.com/RealAlexandreAI/json-repair
|
252
252
|
- Ruby: https://github.com/sashazykov/json-repair-rb
|
253
|
+
- Rust: https://github.com/oramasearch/llm_json
|
253
254
|
---
|
254
255
|
## Star History
|
255
256
|
|
@@ -3,7 +3,7 @@ requires = ["setuptools>=61.0"]
|
|
3
3
|
build-backend = "setuptools.build_meta"
|
4
4
|
[project]
|
5
5
|
name = "json_repair"
|
6
|
-
version = "0.
|
6
|
+
version = "0.46.1"
|
7
7
|
license = {file = "LICENSE"}
|
8
8
|
authors = [
|
9
9
|
{ name="Stefano Baccianella", email="4247706+mangiucugna@users.noreply.github.com" },
|
@@ -72,7 +72,7 @@ target-version = "py313"
|
|
72
72
|
# Simplifications (e.g., if x == True → if x) - SIM
|
73
73
|
# Pyupgrade – safe modernization (e.g., str() → f"") - UP
|
74
74
|
|
75
|
-
select = ['A', 'B', 'C90', 'E', 'F', 'I', 'PLC', 'PLE', 'PLW', 'S', 'SIM', 'TID',
|
75
|
+
select = ['A', 'ARG', 'B', 'C4', 'C90', 'COM', 'E', 'F', 'I', 'PLC', 'PLE', 'PLW', 'Q', 'S', 'SIM', 'TID','UP', 'W']
|
76
76
|
# Only enable these RUF rules
|
77
77
|
extend-select = [
|
78
78
|
"RUF001", # ambiguous Unicode
|
@@ -81,7 +81,7 @@ extend-select = [
|
|
81
81
|
"RUF016", # unnecessary else after return (optional)
|
82
82
|
"RUF018", # unnecessary else after raise (optional)
|
83
83
|
]
|
84
|
-
ignore = ["E501", "C901", "
|
84
|
+
ignore = ["S101", "E501", "C901", "COM812"]
|
85
85
|
|
86
86
|
# Allow fix for all enabled rules (when `--fix`) is provided.
|
87
87
|
fixable = ["ALL"]
|
@@ -41,7 +41,7 @@ class JSONParser:
|
|
41
41
|
self.log = self._log
|
42
42
|
else:
|
43
43
|
# No-op
|
44
|
-
self.log = lambda *args, **kwargs: None
|
44
|
+
self.log = lambda *args, **kwargs: None # noqa: ARG005
|
45
45
|
# When the json to be repaired is the accumulation of streaming json at a certain moment.
|
46
46
|
# e.g. json obtained from llm response.
|
47
47
|
# If this parameter to True will keep the repair results stable. For example:
|
@@ -67,6 +67,9 @@ class JSONParser:
|
|
67
67
|
# replace the last entry with the new one since the new one seems an update
|
68
68
|
json.pop()
|
69
69
|
json.append(j)
|
70
|
+
else:
|
71
|
+
# this was a bust, move the index
|
72
|
+
self.index += 1
|
70
73
|
# If nothing extra was found, don't return an array
|
71
74
|
if len(json) == 1:
|
72
75
|
self.log(
|
@@ -231,7 +234,20 @@ class JSONParser:
|
|
231
234
|
char = self.get_char_at()
|
232
235
|
while char and char not in ["]", "}"]:
|
233
236
|
self.skip_whitespaces_at()
|
234
|
-
value =
|
237
|
+
value: JSONReturnType = ""
|
238
|
+
if char in self.STRING_DELIMITERS:
|
239
|
+
# Sometimes it can happen that LLMs forget to start an object and then you think it's a string in an array
|
240
|
+
# So we are going to check if this string is followed by a : or not
|
241
|
+
# And either parse the string or parse the object
|
242
|
+
i = 1
|
243
|
+
i = self.skip_to_character(char, i)
|
244
|
+
i = self.skip_whitespaces_at(idx=i + 1, move_main_index=False)
|
245
|
+
if self.get_char_at(i) == ":":
|
246
|
+
value = self.parse_object()
|
247
|
+
else:
|
248
|
+
value = self.parse_string()
|
249
|
+
else:
|
250
|
+
value = self.parse_json()
|
235
251
|
|
236
252
|
# It is possible that parse_json() returns nothing valid, so we increase by 1
|
237
253
|
if value == "":
|
@@ -6,7 +6,7 @@ class ObjectComparer: # pragma: no cover
|
|
6
6
|
pass # No operation performed in the constructor
|
7
7
|
|
8
8
|
@staticmethod
|
9
|
-
def is_same_object(obj1: Any, obj2: Any
|
9
|
+
def is_same_object(obj1: Any, obj2: Any) -> bool:
|
10
10
|
"""
|
11
11
|
Recursively compares two objects and ensures that:
|
12
12
|
- Their types match
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: json_repair
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.46.1
|
4
4
|
Summary: A package to repair broken json strings
|
5
5
|
Author-email: Stefano Baccianella <4247706+mangiucugna@users.noreply.github.com>
|
6
6
|
License: MIT License
|
@@ -38,7 +38,7 @@ License-File: LICENSE
|
|
38
38
|
Dynamic: license-file
|
39
39
|
|
40
40
|
[](https://pypi.org/project/json-repair/)
|
41
|
-

|
42
42
|
[](https://pypi.org/project/json-repair/)
|
43
43
|
[](https://github.com/sponsors/mangiucugna)
|
44
44
|
[](https://github.com/mangiucugna/json_repair/stargazers)
|
@@ -289,6 +289,7 @@ You will need owner access to this repository
|
|
289
289
|
- Typescript: https://github.com/josdejong/jsonrepair
|
290
290
|
- Go: https://github.com/RealAlexandreAI/json-repair
|
291
291
|
- Ruby: https://github.com/sashazykov/json-repair-rb
|
292
|
+
- Rust: https://github.com/oramasearch/llm_json
|
292
293
|
---
|
293
294
|
## Star History
|
294
295
|
|
@@ -193,6 +193,7 @@ def test_array_edge_cases():
|
|
193
193
|
== '{"key": ["lorem \\"ipsum\\" dolor \\"sit\\" amet, \\"consectetur\\" ", "lorem \\"ipsum\\" dolor", "lorem"]}'
|
194
194
|
)
|
195
195
|
assert repair_json('{"k"e"y": "value"}') == '{"k\\"e\\"y": "value"}'
|
196
|
+
assert repair_json('["key":"value"}]') == '[{"key": "value"}]'
|
196
197
|
|
197
198
|
|
198
199
|
def test_escaping():
|
@@ -19,7 +19,7 @@ def test_true_true_correct(benchmark):
|
|
19
19
|
mean_time = benchmark.stats.get("median")
|
20
20
|
|
21
21
|
# Define your time threshold in seconds
|
22
|
-
max_time =
|
22
|
+
max_time = 3 / 10**3 # 3 millisecond
|
23
23
|
|
24
24
|
# Assert that the average time is below the threshold
|
25
25
|
assert mean_time < max_time, (
|
@@ -34,7 +34,7 @@ def test_true_true_incorrect(benchmark):
|
|
34
34
|
mean_time = benchmark.stats.get("median")
|
35
35
|
|
36
36
|
# Define your time threshold in seconds
|
37
|
-
max_time =
|
37
|
+
max_time = 3 / 10**3 # 3 millisecond
|
38
38
|
|
39
39
|
# Assert that the average time is below the threshold
|
40
40
|
assert mean_time < max_time, (
|
@@ -62,7 +62,7 @@ def test_true_false_incorrect(benchmark):
|
|
62
62
|
mean_time = benchmark.stats.get("median")
|
63
63
|
|
64
64
|
# Define your time threshold in seconds
|
65
|
-
max_time =
|
65
|
+
max_time = 3 / 10**3 # 3 millisecond
|
66
66
|
|
67
67
|
# Assert that the average time is below the threshold
|
68
68
|
assert mean_time < max_time, (
|
@@ -76,7 +76,7 @@ def test_false_true_correct(benchmark):
|
|
76
76
|
mean_time = benchmark.stats.get("median")
|
77
77
|
|
78
78
|
# Define your time threshold in seconds
|
79
|
-
max_time =
|
79
|
+
max_time = 3 / 10**3 # 3 millisecond
|
80
80
|
|
81
81
|
# Assert that the average time is below the threshold
|
82
82
|
assert mean_time < max_time, (
|
@@ -90,7 +90,7 @@ def test_false_true_incorrect(benchmark):
|
|
90
90
|
mean_time = benchmark.stats.get("median")
|
91
91
|
|
92
92
|
# Define your time threshold in seconds
|
93
|
-
max_time =
|
93
|
+
max_time = 3 / 10**3 # 3 millisecond
|
94
94
|
|
95
95
|
# Assert that the average time is below the threshold
|
96
96
|
assert mean_time < max_time, (
|
@@ -118,7 +118,7 @@ def test_false_false_incorrect(benchmark):
|
|
118
118
|
mean_time = benchmark.stats.get("median")
|
119
119
|
|
120
120
|
# Define your time threshold in seconds
|
121
|
-
max_time =
|
121
|
+
max_time = 3 / 10**3 # 3 millisecond
|
122
122
|
|
123
123
|
# Assert that the average time is below the threshold
|
124
124
|
assert mean_time < max_time, (
|
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
|