json-repair 0.29.1__tar.gz → 0.29.3__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
Files changed (20) hide show
  1. {json_repair-0.29.1/src/json_repair.egg-info → json_repair-0.29.3}/PKG-INFO +41 -16
  2. {json_repair-0.29.1 → json_repair-0.29.3}/README.md +40 -15
  3. {json_repair-0.29.1 → json_repair-0.29.3}/pyproject.toml +1 -1
  4. json_repair-0.29.3/src/json_repair/json_context.py +69 -0
  5. json_repair-0.29.1/src/json_repair/json_repair.py → json_repair-0.29.3/src/json_repair/json_parser.py +151 -375
  6. json_repair-0.29.3/src/json_repair/json_repair.py +182 -0
  7. json_repair-0.29.3/src/json_repair/string_file_wrapper.py +98 -0
  8. {json_repair-0.29.1 → json_repair-0.29.3/src/json_repair.egg-info}/PKG-INFO +41 -16
  9. {json_repair-0.29.1 → json_repair-0.29.3}/src/json_repair.egg-info/SOURCES.txt +3 -0
  10. {json_repair-0.29.1 → json_repair-0.29.3}/tests/test_json_repair.py +2 -0
  11. {json_repair-0.29.1 → json_repair-0.29.3}/tests/test_performance.py +6 -6
  12. {json_repair-0.29.1 → json_repair-0.29.3}/LICENSE +0 -0
  13. {json_repair-0.29.1 → json_repair-0.29.3}/setup.cfg +0 -0
  14. {json_repair-0.29.1 → json_repair-0.29.3}/src/json_repair/__init__.py +0 -0
  15. {json_repair-0.29.1 → json_repair-0.29.3}/src/json_repair/__main__.py +0 -0
  16. {json_repair-0.29.1 → json_repair-0.29.3}/src/json_repair/py.typed +0 -0
  17. {json_repair-0.29.1 → json_repair-0.29.3}/src/json_repair.egg-info/dependency_links.txt +0 -0
  18. {json_repair-0.29.1 → json_repair-0.29.3}/src/json_repair.egg-info/entry_points.txt +0 -0
  19. {json_repair-0.29.1 → json_repair-0.29.3}/src/json_repair.egg-info/top_level.txt +0 -0
  20. {json_repair-0.29.1 → json_repair-0.29.3}/tests/test_coverage.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: json_repair
3
- Version: 0.29.1
3
+ Version: 0.29.3
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.1"
6
+ version = "0.29.3"
7
7
  license = {file = "LICENSE"}
8
8
  authors = [
9
9
  { name="Stefano Baccianella", email="4247706+mangiucugna@users.noreply.github.com" },
@@ -0,0 +1,69 @@
1
+ from enum import Enum, auto
2
+ from typing import List
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
+
15
+ def set(self, value: ContextValues) -> None:
16
+ """
17
+ Set a new context value.
18
+
19
+ Args:
20
+ value (ContextValues): The context value to be added.
21
+
22
+ Returns:
23
+ None
24
+ """
25
+ # If a value is provided update the context variable and save in stack
26
+ if value:
27
+ self.context.append(value)
28
+
29
+ def reset(self) -> None:
30
+ """
31
+ Remove the most recent context value.
32
+
33
+ Returns:
34
+ None
35
+ """
36
+ self.context.pop()
37
+
38
+ def is_current(self, context: ContextValues) -> bool:
39
+ """
40
+ Check if the given context is the current (most recent) context.
41
+
42
+ Args:
43
+ context (ContextValues): The context value to check.
44
+
45
+ Returns:
46
+ bool: True if the given context is the same as the most recent context in the stack, False otherwise.
47
+ """
48
+ return self.context[-1] == context
49
+
50
+ def is_any(self, context: ContextValues) -> bool:
51
+ """
52
+ Check if the given context exists anywhere in the context stack.
53
+
54
+ Args:
55
+ context (ContextValues): The context value to check.
56
+
57
+ Returns:
58
+ bool: True if the given context exists in the stack, False otherwise.
59
+ """
60
+ return context in self.context
61
+
62
+ def is_empty(self) -> bool:
63
+ """
64
+ Check if the context stack is empty.
65
+
66
+ Returns:
67
+ bool: True if the context stack is empty, False otherwise.
68
+ """
69
+ return len(self.context) == 0