json-repair 0.8.0__py3-none-any.whl → 0.8.1__py3-none-any.whl
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/json_repair.py +3 -0
- {json_repair-0.8.0.dist-info → json_repair-0.8.1.dist-info}/METADATA +21 -28
- json_repair-0.8.1.dist-info/RECORD +7 -0
- json_repair-0.8.0.dist-info/RECORD +0 -7
- {json_repair-0.8.0.dist-info → json_repair-0.8.1.dist-info}/LICENSE +0 -0
- {json_repair-0.8.0.dist-info → json_repair-0.8.1.dist-info}/WHEEL +0 -0
- {json_repair-0.8.0.dist-info → json_repair-0.8.1.dist-info}/top_level.txt +0 -0
json_repair/json_repair.py
CHANGED
@@ -247,6 +247,9 @@ class JSONParser:
|
|
247
247
|
if number_str:
|
248
248
|
if "." in number_str or "e" in number_str or "E" in number_str:
|
249
249
|
return float(number_str)
|
250
|
+
elif number_str == "-":
|
251
|
+
# If there is a stray "-" this will throw an exception, throw away this character
|
252
|
+
return self.parse_json()
|
250
253
|
else:
|
251
254
|
return int(number_str)
|
252
255
|
else:
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: json_repair
|
3
|
-
Version: 0.8.
|
3
|
+
Version: 0.8.1
|
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
|
@@ -49,26 +49,34 @@ I searched for a lightweight python package that was able to reliably fix this p
|
|
49
49
|
|
50
50
|
# How to use
|
51
51
|
from json_repair import repair_json
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
# Not even this library could fix this JSON
|
52
|
+
|
53
|
+
good_json_string = repair_json(bad_json_string)
|
54
|
+
# If the string was super broken this will return an empty string
|
56
55
|
|
57
56
|
You can use this library to completely replace `json.loads()`:
|
58
57
|
|
59
58
|
import json_repair
|
60
|
-
|
61
|
-
|
62
|
-
except Exception:
|
63
|
-
# Not even this library could fix this JSON
|
59
|
+
|
60
|
+
decoded_object = json_repair.loads(json_string)
|
64
61
|
|
65
62
|
or just
|
66
63
|
|
67
64
|
import json_repair
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
65
|
+
|
66
|
+
decoded_object = json_repair.repair_json(json_string, return_objects=True)
|
67
|
+
|
68
|
+
### Performance considerations
|
69
|
+
If you find this library too slow because is using `json.loads()` you can skip that by passing `skip_json_loads=True` to `repair_json`. Like:
|
70
|
+
|
71
|
+
from json_repair import repair_json
|
72
|
+
|
73
|
+
good_json_string = repair_json(bad_json_string, skip_json_loads=True)
|
74
|
+
|
75
|
+
I made a choice of not using any fast json library to avoid having any external dependency, so that anybody can use it regardless of their stack.
|
76
|
+
|
77
|
+
Some rules of thumb to use:
|
78
|
+
- Setting `return_objects=True` will always be faster because the parser returns an object already and it doesn't have serialize that object to JSON
|
79
|
+
- `skip_json_loads` is faster only if you 100% know that the string is not a valid JSON
|
72
80
|
|
73
81
|
## Adding to requirements
|
74
82
|
**Please pin this library only on the major version!**
|
@@ -80,21 +88,6 @@ To ensure that you only pin the major version of this library in your `requireme
|
|
80
88
|
|
81
89
|
In this example, any version that starts with `0.` will be acceptable, allowing for updates on minor and patch versions.
|
82
90
|
|
83
|
-
## Performance considerations
|
84
|
-
If you find this library too slow because is using `json.loads()` you can skip that by passing `skip_json_loads=True` to `repair_json`. Like:
|
85
|
-
|
86
|
-
from json_repair import repair_json
|
87
|
-
try:
|
88
|
-
good_json_string = repair_json(bad_json_string, skip_json_loads=True)
|
89
|
-
except Exception:
|
90
|
-
# Not even this library could fix this JSON
|
91
|
-
|
92
|
-
I made a choice of not using any fast json library to avoid having any external dependency, so that anybody can use it regardless of their stack.
|
93
|
-
|
94
|
-
Some rules of thumb to use:
|
95
|
-
- Setting `return_objects=True` will always be faster because the parser returns an object already and it doesn't have serialize that object to JSON
|
96
|
-
- `skip_json_loads` is faster only if you 100% know that the string is not a valid JSON
|
97
|
-
|
98
91
|
# How it works
|
99
92
|
This module will parse the JSON file following the BNF definition:
|
100
93
|
|
@@ -0,0 +1,7 @@
|
|
1
|
+
json_repair/__init__.py,sha256=p9mZnte8Bg18NcxqgJ7vopH2gQv_XbZ0dRnk686QuRE,92
|
2
|
+
json_repair/json_repair.py,sha256=bngfZDyue6iwlsGIehK2QGfxN9XBM_rrR38lUe5jyVM,13263
|
3
|
+
json_repair-0.8.1.dist-info/LICENSE,sha256=wrjQo8MhNrNCicXtMe3MHmS-fx8AmQk1ue8AQwiiFV8,1076
|
4
|
+
json_repair-0.8.1.dist-info/METADATA,sha256=-T0p-tSwV-_GoqK5d6DiAkSxUAPTgVQtXDIzv81ZSM8,6311
|
5
|
+
json_repair-0.8.1.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
|
6
|
+
json_repair-0.8.1.dist-info/top_level.txt,sha256=7-VZwZN2CgB_n0NlSLk-rEUFh8ug21lESbsblOYuZqw,12
|
7
|
+
json_repair-0.8.1.dist-info/RECORD,,
|
@@ -1,7 +0,0 @@
|
|
1
|
-
json_repair/__init__.py,sha256=p9mZnte8Bg18NcxqgJ7vopH2gQv_XbZ0dRnk686QuRE,92
|
2
|
-
json_repair/json_repair.py,sha256=qssQbSmeNR2aORuYccEu4ab1GwistbDVfLx1vRvaqyI,13088
|
3
|
-
json_repair-0.8.0.dist-info/LICENSE,sha256=wrjQo8MhNrNCicXtMe3MHmS-fx8AmQk1ue8AQwiiFV8,1076
|
4
|
-
json_repair-0.8.0.dist-info/METADATA,sha256=j1vfdRjZhqy2or8zYEp7p-IjDxJ_OJ2OODGdtiX3Rbo,6568
|
5
|
-
json_repair-0.8.0.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
|
6
|
-
json_repair-0.8.0.dist-info/top_level.txt,sha256=7-VZwZN2CgB_n0NlSLk-rEUFh8ug21lESbsblOYuZqw,12
|
7
|
-
json_repair-0.8.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|