json-repair 0.15.0__tar.gz → 0.15.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.15.0/src/json_repair.egg-info → json_repair-0.15.2}/PKG-INFO +1 -1
- {json_repair-0.15.0 → json_repair-0.15.2}/pyproject.toml +1 -1
- {json_repair-0.15.0 → json_repair-0.15.2}/src/json_repair/json_repair.py +9 -10
- {json_repair-0.15.0 → json_repair-0.15.2/src/json_repair.egg-info}/PKG-INFO +1 -1
- {json_repair-0.15.0 → json_repair-0.15.2}/tests/test_json_repair.py +9 -3
- {json_repair-0.15.0 → json_repair-0.15.2}/LICENSE +0 -0
- {json_repair-0.15.0 → json_repair-0.15.2}/README.md +0 -0
- {json_repair-0.15.0 → json_repair-0.15.2}/setup.cfg +0 -0
- {json_repair-0.15.0 → json_repair-0.15.2}/src/json_repair/__init__.py +0 -0
- {json_repair-0.15.0 → json_repair-0.15.2}/src/json_repair.egg-info/SOURCES.txt +0 -0
- {json_repair-0.15.0 → json_repair-0.15.2}/src/json_repair.egg-info/dependency_links.txt +0 -0
- {json_repair-0.15.0 → json_repair-0.15.2}/src/json_repair.egg-info/top_level.txt +0 -0
- {json_repair-0.15.0 → json_repair-0.15.2}/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.15.
|
6
|
+
version = "0.15.2"
|
7
7
|
license = {file = "LICENSE"}
|
8
8
|
authors = [
|
9
9
|
{ name="Stefano Baccianella", email="4247706+mangiucugna@users.noreply.github.com" },
|
@@ -329,7 +329,7 @@ class JSONParser:
|
|
329
329
|
def parse_number(self) -> Union[float, int, str]:
|
330
330
|
# <number> is a valid real number expressed in one of a number of given formats
|
331
331
|
number_str = ""
|
332
|
-
number_chars = set("0123456789-.eE")
|
332
|
+
number_chars = set("0123456789-.eE/")
|
333
333
|
char = self.get_char_at()
|
334
334
|
while char and char in number_chars:
|
335
335
|
number_str += char
|
@@ -453,27 +453,26 @@ def repair_json(
|
|
453
453
|
|
454
454
|
|
455
455
|
def loads(
|
456
|
-
json_str: str,
|
456
|
+
json_str: str, skip_json_loads: bool = False, logging: bool = False
|
457
457
|
) -> Union[Dict[str, Any], List[Any], str, float, int, bool, None]:
|
458
458
|
"""
|
459
459
|
This function works like `json.loads()` except that it will fix your JSON in the process.
|
460
460
|
It is a wrapper around the `repair_json()` function with `return_objects=True`.
|
461
461
|
"""
|
462
|
-
return repair_json(json_str, True)
|
462
|
+
return repair_json(json_str, True, skip_json_loads, logging)
|
463
463
|
|
464
464
|
|
465
|
-
def load(
|
466
|
-
|
465
|
+
def load(
|
466
|
+
fp: TextIO, skip_json_loads: bool = False, logging: bool = False
|
467
|
+
) -> Union[Dict[str, Any], List[Any], str, float, int, bool, None]:
|
468
|
+
return loads(fp.read(), skip_json_loads, logging)
|
467
469
|
|
468
470
|
|
469
471
|
def from_file(
|
470
|
-
filename: str,
|
472
|
+
filename: str, skip_json_loads: bool = False, logging: bool = False
|
471
473
|
) -> Union[Dict[str, Any], List[Any], str, float, int, bool, None]:
|
472
474
|
fd = open(filename)
|
473
|
-
jsonobj = load(fd)
|
475
|
+
jsonobj = load(fd, skip_json_loads, logging)
|
474
476
|
fd.close()
|
475
477
|
|
476
478
|
return jsonobj
|
477
|
-
|
478
|
-
|
479
|
-
print(repair_json('{ "key": "value", "key2": }', logging=True))
|
@@ -1,4 +1,4 @@
|
|
1
|
-
from src.json_repair.json_repair import from_file, repair_json
|
1
|
+
from src.json_repair.json_repair import from_file, repair_json, loads
|
2
2
|
|
3
3
|
|
4
4
|
def test_repair_json():
|
@@ -110,6 +110,7 @@ def test_repair_json():
|
|
110
110
|
assert repair_json('{""answer":[{""traits":""Female aged 60+",""answer1":""5"}]}') == '{"answer": [{"traits": "Female aged 60+", "answer1": "5"}]}'
|
111
111
|
assert repair_json('{"key":"",}') == '{"key": ",}"}'
|
112
112
|
assert repair_json('{ "words": abcdef", "numbers": 12345", "words2": ghijkl" }') == '{"words": "abcdef", "numbers": 12345, "words2": "ghijkl"}'
|
113
|
+
assert repair_json('{"key": 1/3}') == '{"key": "1/3"}'
|
113
114
|
|
114
115
|
|
115
116
|
def test_repair_json_with_objects():
|
@@ -259,7 +260,7 @@ def test_repair_json_skip_json_loads():
|
|
259
260
|
assert repair_json('{"key": true, "key2": false, "key3": null}', skip_json_loads=True) == '{"key": true, "key2": false, "key3": null}'
|
260
261
|
assert repair_json('{"key": true, "key2": false, "key3": null}', return_objects=True, skip_json_loads=True) == {"key": True, "key2": False, "key3": None}
|
261
262
|
assert repair_json('{"key": true, "key2": false, "key3": }', skip_json_loads=True) == '{"key": true, "key2": false, "key3": ""}'
|
262
|
-
assert
|
263
|
+
assert loads('{"key": true, "key2": false, "key3": }', skip_json_loads=True) == {"key": True, "key2": False, "key3": ""}
|
263
264
|
|
264
265
|
def test_repair_json_from_file():
|
265
266
|
import os
|
@@ -272,8 +273,13 @@ def test_repair_json_from_file():
|
|
272
273
|
with os.fdopen(temp_fd, 'w') as tmp:
|
273
274
|
tmp.write("{")
|
274
275
|
|
275
|
-
assert(from_file(temp_path)) == {}
|
276
|
+
assert(from_file(temp_path, logging=True)) == ({},[])
|
276
277
|
|
277
278
|
finally:
|
278
279
|
# Clean up - delete the temporary file
|
279
280
|
os.remove(temp_path)
|
281
|
+
|
282
|
+
|
283
|
+
assert repair_json('{"key": 1/3, "foo": "bar"}') == '{"key": "1/3", "foo": "bar"}'
|
284
|
+
assert repair_json('{"here": "now", "key": 1/3, "foo": "bar"}') == '{"here": "now", "key": "1/3", "foo": "bar"}'
|
285
|
+
assert repair_json('{"key": 12345/67890}') == '{"key": "12345/67890"}'
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|