json-repair 0.29.2__tar.gz → 0.29.4__tar.gz
Sign up to get free protection for your applications and to get access to all the features.
- {json_repair-0.29.2/src/json_repair.egg-info → json_repair-0.29.4}/PKG-INFO +41 -16
- {json_repair-0.29.2 → json_repair-0.29.4}/README.md +40 -15
- {json_repair-0.29.2 → json_repair-0.29.4}/pyproject.toml +1 -1
- json_repair-0.29.4/src/json_repair/json_context.py +45 -0
- json_repair-0.29.2/src/json_repair/json_repair.py → json_repair-0.29.4/src/json_repair/json_parser.py +119 -358
- json_repair-0.29.4/src/json_repair/json_repair.py +182 -0
- json_repair-0.29.4/src/json_repair/string_file_wrapper.py +98 -0
- {json_repair-0.29.2 → json_repair-0.29.4/src/json_repair.egg-info}/PKG-INFO +41 -16
- {json_repair-0.29.2 → json_repair-0.29.4}/src/json_repair.egg-info/SOURCES.txt +3 -0
- {json_repair-0.29.2 → json_repair-0.29.4}/tests/test_performance.py +6 -6
- {json_repair-0.29.2 → json_repair-0.29.4}/LICENSE +0 -0
- {json_repair-0.29.2 → json_repair-0.29.4}/setup.cfg +0 -0
- {json_repair-0.29.2 → json_repair-0.29.4}/src/json_repair/__init__.py +0 -0
- {json_repair-0.29.2 → json_repair-0.29.4}/src/json_repair/__main__.py +0 -0
- {json_repair-0.29.2 → json_repair-0.29.4}/src/json_repair/py.typed +0 -0
- {json_repair-0.29.2 → json_repair-0.29.4}/src/json_repair.egg-info/dependency_links.txt +0 -0
- {json_repair-0.29.2 → json_repair-0.29.4}/src/json_repair.egg-info/entry_points.txt +0 -0
- {json_repair-0.29.2 → json_repair-0.29.4}/src/json_repair.egg-info/top_level.txt +0 -0
- {json_repair-0.29.2 → json_repair-0.29.4}/tests/test_coverage.py +0 -0
- {json_repair-0.29.2 → json_repair-0.29.4}/tests/test_json_repair.py +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: json_repair
|
3
|
-
Version: 0.29.
|
3
|
+
Version: 0.29.4
|
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
|
@@ -45,21 +45,6 @@ This simple package can be used to fix an invalid json string. To know all cases
|
|
45
45
|
|
46
46
|
Inspired by https://github.com/josdejong/jsonrepair
|
47
47
|
|
48
|
-
---
|
49
|
-
# How to cite
|
50
|
-
If you are using this library in your academic work (as I know many folks are) please find the BibTex here:
|
51
|
-
|
52
|
-
@software{Baccianella_JSON_Repair_-_2024,
|
53
|
-
author = {Baccianella, Stefano},
|
54
|
-
month = aug,
|
55
|
-
title = {{JSON Repair - A python module to repair invalid JSON, commonly used to parse the output of LLMs}},
|
56
|
-
url = {https://github.com/mangiucugna/json_repair},
|
57
|
-
version = {0.28.3},
|
58
|
-
year = {2024}
|
59
|
-
}
|
60
|
-
|
61
|
-
Thank you for citing my work and please send me a link to the paper if you can!
|
62
|
-
|
63
48
|
---
|
64
49
|
# Offer me a beer
|
65
50
|
If you find this library useful, you can help me by donating toward my monthly beer budget here: https://github.com/sponsors/mangiucugna
|
@@ -79,7 +64,30 @@ I searched for a lightweight python package that was able to reliably fix this p
|
|
79
64
|
|
80
65
|
*So I wrote one*
|
81
66
|
|
67
|
+
# Supported use cases
|
68
|
+
|
69
|
+
### Fixing Syntax Errors in JSON
|
70
|
+
|
71
|
+
- Missing quotes, misplaced commas, unescaped characters, and incomplete key-value pairs.
|
72
|
+
- Missing quotation marks, improperly formatted values (true, false, null), and repairs corrupted key-value structures.
|
73
|
+
|
74
|
+
### Repairing Malformed JSON Arrays and Objects
|
75
|
+
|
76
|
+
- Incomplete or broken arrays/objects by adding necessary elements (e.g., commas, brackets) or default values (null, "").
|
77
|
+
- The library can process JSON that includes extra non-JSON characters like comments or improperly placed characters, cleaning them up while maintaining valid structure.
|
78
|
+
|
79
|
+
### Auto-Completion for Missing JSON Values
|
80
|
+
|
81
|
+
- Automatically completes missing values in JSON fields with reasonable defaults (like empty strings or null), ensuring validity.
|
82
|
+
|
82
83
|
# How to use
|
84
|
+
|
85
|
+
Install the library with pip
|
86
|
+
|
87
|
+
pip install json-repair
|
88
|
+
|
89
|
+
then you can use use it in your code like this
|
90
|
+
|
83
91
|
from json_repair import repair_json
|
84
92
|
|
85
93
|
good_json_string = repair_json(bad_json_string)
|
@@ -185,6 +193,23 @@ To ensure that you only pin the major version of this library in your `requireme
|
|
185
193
|
|
186
194
|
In this example, any version that starts with `0.` will be acceptable, allowing for updates on minor and patch versions.
|
187
195
|
|
196
|
+
---
|
197
|
+
# How to cite
|
198
|
+
If you are using this library in your academic work (as I know many folks are) please find the BibTex here:
|
199
|
+
|
200
|
+
@software{Baccianella_JSON_Repair_-_2024,
|
201
|
+
author = {Baccianella, Stefano},
|
202
|
+
month = aug,
|
203
|
+
title = {{JSON Repair - A python module to repair invalid JSON, commonly used to parse the output of LLMs}},
|
204
|
+
url = {https://github.com/mangiucugna/json_repair},
|
205
|
+
version = {0.28.3},
|
206
|
+
year = {2024}
|
207
|
+
}
|
208
|
+
|
209
|
+
Thank you for citing my work and please send me a link to the paper if you can!
|
210
|
+
|
211
|
+
---
|
212
|
+
|
188
213
|
# How it works
|
189
214
|
This module will parse the JSON file following the BNF definition:
|
190
215
|
|
@@ -7,21 +7,6 @@ This simple package can be used to fix an invalid json string. To know all cases
|
|
7
7
|
|
8
8
|
Inspired by https://github.com/josdejong/jsonrepair
|
9
9
|
|
10
|
-
---
|
11
|
-
# How to cite
|
12
|
-
If you are using this library in your academic work (as I know many folks are) please find the BibTex here:
|
13
|
-
|
14
|
-
@software{Baccianella_JSON_Repair_-_2024,
|
15
|
-
author = {Baccianella, Stefano},
|
16
|
-
month = aug,
|
17
|
-
title = {{JSON Repair - A python module to repair invalid JSON, commonly used to parse the output of LLMs}},
|
18
|
-
url = {https://github.com/mangiucugna/json_repair},
|
19
|
-
version = {0.28.3},
|
20
|
-
year = {2024}
|
21
|
-
}
|
22
|
-
|
23
|
-
Thank you for citing my work and please send me a link to the paper if you can!
|
24
|
-
|
25
10
|
---
|
26
11
|
# Offer me a beer
|
27
12
|
If you find this library useful, you can help me by donating toward my monthly beer budget here: https://github.com/sponsors/mangiucugna
|
@@ -41,7 +26,30 @@ I searched for a lightweight python package that was able to reliably fix this p
|
|
41
26
|
|
42
27
|
*So I wrote one*
|
43
28
|
|
29
|
+
# Supported use cases
|
30
|
+
|
31
|
+
### Fixing Syntax Errors in JSON
|
32
|
+
|
33
|
+
- Missing quotes, misplaced commas, unescaped characters, and incomplete key-value pairs.
|
34
|
+
- Missing quotation marks, improperly formatted values (true, false, null), and repairs corrupted key-value structures.
|
35
|
+
|
36
|
+
### Repairing Malformed JSON Arrays and Objects
|
37
|
+
|
38
|
+
- Incomplete or broken arrays/objects by adding necessary elements (e.g., commas, brackets) or default values (null, "").
|
39
|
+
- The library can process JSON that includes extra non-JSON characters like comments or improperly placed characters, cleaning them up while maintaining valid structure.
|
40
|
+
|
41
|
+
### Auto-Completion for Missing JSON Values
|
42
|
+
|
43
|
+
- Automatically completes missing values in JSON fields with reasonable defaults (like empty strings or null), ensuring validity.
|
44
|
+
|
44
45
|
# How to use
|
46
|
+
|
47
|
+
Install the library with pip
|
48
|
+
|
49
|
+
pip install json-repair
|
50
|
+
|
51
|
+
then you can use use it in your code like this
|
52
|
+
|
45
53
|
from json_repair import repair_json
|
46
54
|
|
47
55
|
good_json_string = repair_json(bad_json_string)
|
@@ -147,6 +155,23 @@ To ensure that you only pin the major version of this library in your `requireme
|
|
147
155
|
|
148
156
|
In this example, any version that starts with `0.` will be acceptable, allowing for updates on minor and patch versions.
|
149
157
|
|
158
|
+
---
|
159
|
+
# How to cite
|
160
|
+
If you are using this library in your academic work (as I know many folks are) please find the BibTex here:
|
161
|
+
|
162
|
+
@software{Baccianella_JSON_Repair_-_2024,
|
163
|
+
author = {Baccianella, Stefano},
|
164
|
+
month = aug,
|
165
|
+
title = {{JSON Repair - A python module to repair invalid JSON, commonly used to parse the output of LLMs}},
|
166
|
+
url = {https://github.com/mangiucugna/json_repair},
|
167
|
+
version = {0.28.3},
|
168
|
+
year = {2024}
|
169
|
+
}
|
170
|
+
|
171
|
+
Thank you for citing my work and please send me a link to the paper if you can!
|
172
|
+
|
173
|
+
---
|
174
|
+
|
150
175
|
# How it works
|
151
176
|
This module will parse the JSON file following the BNF definition:
|
152
177
|
|
@@ -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.29.
|
6
|
+
version = "0.29.4"
|
7
7
|
license = {file = "LICENSE"}
|
8
8
|
authors = [
|
9
9
|
{ name="Stefano Baccianella", email="4247706+mangiucugna@users.noreply.github.com" },
|
@@ -0,0 +1,45 @@
|
|
1
|
+
from enum import Enum, auto
|
2
|
+
from typing import List, Optional
|
3
|
+
|
4
|
+
|
5
|
+
class ContextValues(Enum):
|
6
|
+
OBJECT_KEY = auto()
|
7
|
+
OBJECT_VALUE = auto()
|
8
|
+
ARRAY = auto()
|
9
|
+
|
10
|
+
|
11
|
+
class JsonContext:
|
12
|
+
def __init__(self) -> None:
|
13
|
+
self.context: List[ContextValues] = []
|
14
|
+
self.current: Optional[ContextValues] = None
|
15
|
+
self.empty: bool = True
|
16
|
+
|
17
|
+
def set(self, value: ContextValues) -> None:
|
18
|
+
"""
|
19
|
+
Set a new context value.
|
20
|
+
|
21
|
+
Args:
|
22
|
+
value (ContextValues): The context value to be added.
|
23
|
+
|
24
|
+
Returns:
|
25
|
+
None
|
26
|
+
"""
|
27
|
+
# If a value is provided update the context variable and save in stack
|
28
|
+
if value:
|
29
|
+
self.context.append(value)
|
30
|
+
self.current = value
|
31
|
+
self.empty = False
|
32
|
+
|
33
|
+
def reset(self) -> None:
|
34
|
+
"""
|
35
|
+
Remove the most recent context value.
|
36
|
+
|
37
|
+
Returns:
|
38
|
+
None
|
39
|
+
"""
|
40
|
+
try:
|
41
|
+
self.context.pop()
|
42
|
+
self.current = self.context[-1]
|
43
|
+
except IndexError:
|
44
|
+
self.current = None
|
45
|
+
self.empty = True
|