json-repair 0.17.1__tar.gz → 0.17.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.17.1/src/json_repair.egg-info → json_repair-0.17.2}/PKG-INFO +7 -5
- {json_repair-0.17.1 → json_repair-0.17.2}/README.md +6 -4
- {json_repair-0.17.1 → json_repair-0.17.2}/pyproject.toml +1 -1
- {json_repair-0.17.1 → json_repair-0.17.2}/src/json_repair/json_repair.py +11 -15
- {json_repair-0.17.1 → json_repair-0.17.2/src/json_repair.egg-info}/PKG-INFO +7 -5
- {json_repair-0.17.1 → json_repair-0.17.2}/tests/test_json_repair.py +2 -2
- {json_repair-0.17.1 → json_repair-0.17.2}/LICENSE +0 -0
- {json_repair-0.17.1 → json_repair-0.17.2}/setup.cfg +0 -0
- {json_repair-0.17.1 → json_repair-0.17.2}/src/json_repair/__init__.py +0 -0
- {json_repair-0.17.1 → json_repair-0.17.2}/src/json_repair.egg-info/SOURCES.txt +0 -0
- {json_repair-0.17.1 → json_repair-0.17.2}/src/json_repair.egg-info/dependency_links.txt +0 -0
- {json_repair-0.17.1 → json_repair-0.17.2}/src/json_repair.egg-info/top_level.txt +0 -0
- {json_repair-0.17.1 → json_repair-0.17.2}/tests/test_performance.py +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: json_repair
|
3
|
-
Version: 0.17.
|
3
|
+
Version: 0.17.2
|
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
|
@@ -39,6 +39,12 @@ This simple package can be used to fix an invalid json string. To know all cases
|
|
39
39
|
|
40
40
|
Inspired by https://github.com/josdejong/jsonrepair
|
41
41
|
|
42
|
+
---
|
43
|
+
# Offer me a beer
|
44
|
+
If you find this library useful, you can help me by donating toward my monthly beer budget here: https://github.com/sponsors/mangiucugna
|
45
|
+
|
46
|
+
---
|
47
|
+
|
42
48
|
# Motivation
|
43
49
|
Some LLMs are a bit iffy when it comes to returning well formed JSON data, sometimes they skip a parentheses and sometimes they add some words in it, because that's what an LLM does.
|
44
50
|
Luckily, the mistakes LLMs make are simple enough to be fixed without destroying the content.
|
@@ -154,10 +160,6 @@ You will need owner access to this repository
|
|
154
160
|
# Repair JSON in other programming languages
|
155
161
|
- Typescript: https://github.com/josdejong/jsonrepair
|
156
162
|
- Go: https://github.com/RealAlexandreAI/json-repair
|
157
|
-
---
|
158
|
-
# Bonus Content
|
159
|
-
If you need some good Custom Instructions (System Message) to improve your chatbot responses try https://gist.github.com/mangiucugna/7ec015c4266df11be8aa510be0110fe4
|
160
|
-
|
161
163
|
---
|
162
164
|
## Star History
|
163
165
|
|
@@ -2,6 +2,12 @@ This simple package can be used to fix an invalid json string. To know all cases
|
|
2
2
|
|
3
3
|
Inspired by https://github.com/josdejong/jsonrepair
|
4
4
|
|
5
|
+
---
|
6
|
+
# Offer me a beer
|
7
|
+
If you find this library useful, you can help me by donating toward my monthly beer budget here: https://github.com/sponsors/mangiucugna
|
8
|
+
|
9
|
+
---
|
10
|
+
|
5
11
|
# Motivation
|
6
12
|
Some LLMs are a bit iffy when it comes to returning well formed JSON data, sometimes they skip a parentheses and sometimes they add some words in it, because that's what an LLM does.
|
7
13
|
Luckily, the mistakes LLMs make are simple enough to be fixed without destroying the content.
|
@@ -117,10 +123,6 @@ You will need owner access to this repository
|
|
117
123
|
# Repair JSON in other programming languages
|
118
124
|
- Typescript: https://github.com/josdejong/jsonrepair
|
119
125
|
- Go: https://github.com/RealAlexandreAI/json-repair
|
120
|
-
---
|
121
|
-
# Bonus Content
|
122
|
-
If you need some good Custom Instructions (System Message) to improve your chatbot responses try https://gist.github.com/mangiucugna/7ec015c4266df11be8aa510be0110fe4
|
123
|
-
|
124
126
|
---
|
125
127
|
## Star History
|
126
128
|
|
@@ -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.17.
|
6
|
+
version = "0.17.2"
|
7
7
|
license = {file = "LICENSE"}
|
8
8
|
authors = [
|
9
9
|
{ name="Stefano Baccianella", email="4247706+mangiucugna@users.noreply.github.com" },
|
@@ -302,16 +302,6 @@ class JSONParser:
|
|
302
302
|
string_acc += char
|
303
303
|
self.index += 1
|
304
304
|
char = self.get_char_at()
|
305
|
-
# If the string contains an escaped character we should respect that or remove the escape
|
306
|
-
if self.get_char_at(-1) == "\\":
|
307
|
-
if char in [rstring_delimiter, "t", "n", "r", "b", "\\"]:
|
308
|
-
string_acc += char
|
309
|
-
self.index += 1
|
310
|
-
char = self.get_char_at()
|
311
|
-
else:
|
312
|
-
# Remove this character from the final output
|
313
|
-
string_acc = string_acc[:-2] + string_acc[-1:]
|
314
|
-
self.index -= 1
|
315
305
|
# ChatGPT sometimes forget to quote stuff in html tags or markdown, so we do this whole thing here
|
316
306
|
if char == rstring_delimiter:
|
317
307
|
# Special case here, in case of double quotes one after another
|
@@ -495,11 +485,17 @@ class JSONParser:
|
|
495
485
|
context = self.json_fd.read(self.logger["window"] * 2)
|
496
486
|
self.json_fd.seek(self.index)
|
497
487
|
else:
|
498
|
-
|
499
|
-
self.index
|
500
|
-
- self.logger["window"]
|
501
|
-
|
502
|
-
|
488
|
+
start = (
|
489
|
+
self.index - self.logger["window"]
|
490
|
+
if (self.index - self.logger["window"]) >= 0
|
491
|
+
else 0
|
492
|
+
)
|
493
|
+
end = (
|
494
|
+
self.index + self.logger["window"]
|
495
|
+
if (self.index + self.logger["window"]) <= len(self.json_str)
|
496
|
+
else len(self.json_str)
|
497
|
+
)
|
498
|
+
context = self.json_str[start:end]
|
503
499
|
self.logger["log"].append(
|
504
500
|
{
|
505
501
|
"text": text,
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: json_repair
|
3
|
-
Version: 0.17.
|
3
|
+
Version: 0.17.2
|
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
|
@@ -39,6 +39,12 @@ This simple package can be used to fix an invalid json string. To know all cases
|
|
39
39
|
|
40
40
|
Inspired by https://github.com/josdejong/jsonrepair
|
41
41
|
|
42
|
+
---
|
43
|
+
# Offer me a beer
|
44
|
+
If you find this library useful, you can help me by donating toward my monthly beer budget here: https://github.com/sponsors/mangiucugna
|
45
|
+
|
46
|
+
---
|
47
|
+
|
42
48
|
# Motivation
|
43
49
|
Some LLMs are a bit iffy when it comes to returning well formed JSON data, sometimes they skip a parentheses and sometimes they add some words in it, because that's what an LLM does.
|
44
50
|
Luckily, the mistakes LLMs make are simple enough to be fixed without destroying the content.
|
@@ -154,10 +160,6 @@ You will need owner access to this repository
|
|
154
160
|
# Repair JSON in other programming languages
|
155
161
|
- Typescript: https://github.com/josdejong/jsonrepair
|
156
162
|
- Go: https://github.com/RealAlexandreAI/json-repair
|
157
|
-
---
|
158
|
-
# Bonus Content
|
159
|
-
If you need some good Custom Instructions (System Message) to improve your chatbot responses try https://gist.github.com/mangiucugna/7ec015c4266df11be8aa510be0110fe4
|
160
|
-
|
161
163
|
---
|
162
164
|
## Star History
|
163
165
|
|
@@ -7,7 +7,7 @@ def test_repair_json():
|
|
7
7
|
assert repair_json("[{]") == "[]"
|
8
8
|
assert repair_json(" { } ") == "{}"
|
9
9
|
assert repair_json("\"") == '""'
|
10
|
-
assert repair_json("\n") == '""'
|
10
|
+
assert repair_json("\n") == '""'
|
11
11
|
assert repair_json(' {"key": true, "key2": false, "key3": null}') == '{"key": true, "key2": false, "key3": null}'
|
12
12
|
assert repair_json('{"key": TRUE, "key2": FALSE, "key3": Null} ') == '{"key": true, "key2": false, "key3": null}'
|
13
13
|
assert repair_json("{'key': 'string', 'key2': false, \"key3\": null, \"key4\": unquoted}") == '{"key": "string", "key2": false, "key3": null, "key4": "unquoted"}'
|
@@ -56,7 +56,7 @@ def test_repair_json():
|
|
56
56
|
assert repair_json('{"') == '{}'
|
57
57
|
assert repair_json('["') == '[]'
|
58
58
|
assert repair_json("'\"'") == '"\\\""'
|
59
|
-
assert repair_json("'string\"") == '"string\\\""'
|
59
|
+
assert repair_json("'string\"\n\t\le") == '"string\\\"\\n\\t\\\\le"'
|
60
60
|
assert repair_json('{foo: [}') == '{"foo": []}'
|
61
61
|
assert repair_json('''{ "a": "{ b": {} }" }''') == '{"a": "{ b"}'
|
62
62
|
assert repair_json('{"key": "value:value"}') == '{"key": "value:value"}'
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|