json-repair 0.18.0__tar.gz → 0.19.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.18.0/src/json_repair.egg-info → json_repair-0.19.1}/PKG-INFO +1 -1
- {json_repair-0.18.0 → json_repair-0.19.1}/pyproject.toml +1 -1
- {json_repair-0.18.0 → json_repair-0.19.1}/src/json_repair/json_repair.py +15 -1
- {json_repair-0.18.0 → json_repair-0.19.1/src/json_repair.egg-info}/PKG-INFO +1 -1
- {json_repair-0.18.0 → json_repair-0.19.1}/tests/test_json_repair.py +5 -3
- {json_repair-0.18.0 → json_repair-0.19.1}/LICENSE +0 -0
- {json_repair-0.18.0 → json_repair-0.19.1}/README.md +0 -0
- {json_repair-0.18.0 → json_repair-0.19.1}/setup.cfg +0 -0
- {json_repair-0.18.0 → json_repair-0.19.1}/src/json_repair/__init__.py +0 -0
- {json_repair-0.18.0 → json_repair-0.19.1}/src/json_repair.egg-info/SOURCES.txt +0 -0
- {json_repair-0.18.0 → json_repair-0.19.1}/src/json_repair.egg-info/dependency_links.txt +0 -0
- {json_repair-0.18.0 → json_repair-0.19.1}/src/json_repair.egg-info/top_level.txt +0 -0
- {json_repair-0.18.0 → json_repair-0.19.1}/tests/test_performance.py +0 -0
@@ -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.19.1"
|
7
7
|
license = {file = "LICENSE"}
|
8
8
|
authors = [
|
9
9
|
{ name="Stefano Baccianella", email="4247706+mangiucugna@users.noreply.github.com" },
|
@@ -178,7 +178,12 @@ class JSONParser:
|
|
178
178
|
if not value:
|
179
179
|
break
|
180
180
|
|
181
|
-
|
181
|
+
if value == "..." and self.get_char_at(-1) == ".":
|
182
|
+
self.log(
|
183
|
+
"While parsing an array, found a stray '...'; ignoring it", "info"
|
184
|
+
)
|
185
|
+
else:
|
186
|
+
arr.append(value)
|
182
187
|
|
183
188
|
# skip over whitespace after a value but before closing ]
|
184
189
|
char = self.get_char_at()
|
@@ -304,6 +309,15 @@ class JSONParser:
|
|
304
309
|
string_acc += char
|
305
310
|
self.index += 1
|
306
311
|
char = self.get_char_at()
|
312
|
+
if len(string_acc) > 1 and string_acc[-1] == "\\":
|
313
|
+
# This is a special case, if people use real strings this might happen
|
314
|
+
self.log("Found a stray escape sequence, normalizing it", "info")
|
315
|
+
string_acc = string_acc[:-1]
|
316
|
+
if char in [rstring_delimiter, "t", "n", "r", "b", "\\"]:
|
317
|
+
escape_seqs = {"t": "\t", "n": "\n", "r": "\r", "b": "\b"}
|
318
|
+
string_acc += escape_seqs.get(char, char)
|
319
|
+
self.index += 1
|
320
|
+
char = self.get_char_at()
|
307
321
|
# ChatGPT sometimes forget to quote stuff in html tags or markdown, so we do this whole thing here
|
308
322
|
if char == rstring_delimiter:
|
309
323
|
# Special case here, in case of double quotes one after another
|
@@ -39,6 +39,9 @@ def test_repair_json():
|
|
39
39
|
== '{"name": "John", "age": 30, "city": "New York"}'
|
40
40
|
)
|
41
41
|
assert repair_json("[1, 2, 3,") == "[1, 2, 3]"
|
42
|
+
assert repair_json("[1, 2, 3, ...]") == "[1, 2, 3]"
|
43
|
+
assert repair_json("[1, 2, ... , 3]") == "[1, 2, 3]"
|
44
|
+
assert repair_json("[1, 2, '...', 3]") == '[1, 2, "...", 3]'
|
42
45
|
assert (
|
43
46
|
repair_json('{"employees":["John", "Anna",')
|
44
47
|
== '{"employees": ["John", "Anna"]}'
|
@@ -56,7 +59,7 @@ def test_repair_json():
|
|
56
59
|
assert repair_json('{"') == '{}'
|
57
60
|
assert repair_json('["') == '[]'
|
58
61
|
assert repair_json("'\"'") == '"\\\""'
|
59
|
-
assert repair_json("{\"key\": 'string\"\n\t\le'") == '{"key": "string\\"\\n\\
|
62
|
+
assert repair_json("{\"key\": 'string\"\n\t\le'") == '{"key": "string\\"\\n\\tle"}'
|
60
63
|
assert repair_json('{foo: [}') == '{"foo": []}'
|
61
64
|
assert repair_json('''{ "a": "{ b": {} }" }''') == '{"a": "{ b"}'
|
62
65
|
assert repair_json('{"key": "value:value"}') == '{"key": "value:value"}'
|
@@ -107,7 +110,7 @@ def test_repair_json():
|
|
107
110
|
{ "key": "value" }
|
108
111
|
```""") == '{"key": "value"}'
|
109
112
|
assert repair_json('````{ "key": "value" }```') == '{"key": "value"}'
|
110
|
-
assert repair_json(r'{"real_content": "Some string: Some other string Some string <a href=\"https://domain.com\">Some link</a>"') == r'{"real_content": "Some string: Some other string Some string <a href
|
113
|
+
assert repair_json(r'{"real_content": "Some string: Some other string \t Some string <a href=\"https://domain.com\">Some link</a>"') == r'{"real_content": "Some string: Some other string \t Some string <a href=\"https://domain.com\">Some link</a>"}'
|
111
114
|
assert repair_json('{"key_1\n": "value"}') == '{"key_1": "value"}'
|
112
115
|
assert repair_json('{"key\t_": "value"}') == '{"key\\t_": "value"}'
|
113
116
|
assert repair_json('{""answer"":[{""traits"":''Female aged 60+'',""answer1"":""5""}]}') == '{"answer": [{"traits": "Female aged 60+", "answer1": "5"}]}'
|
@@ -156,7 +159,6 @@ def test_repair_json_with_objects():
|
|
156
159
|
"age": 30,
|
157
160
|
"city": "New York",
|
158
161
|
}
|
159
|
-
assert repair_json("[1, 2, 3,", return_objects=True) == [1, 2, 3]
|
160
162
|
assert repair_json('{"employees":["John", "Anna",', return_objects=True) == {
|
161
163
|
"employees": ["John", "Anna"]
|
162
164
|
}
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|