json-repair 0.25.0__py3-none-any.whl → 0.25.2__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 +41 -43
- {json_repair-0.25.0.dist-info → json_repair-0.25.2.dist-info}/METADATA +6 -1
- json_repair-0.25.2.dist-info/RECORD +7 -0
- {json_repair-0.25.0.dist-info → json_repair-0.25.2.dist-info}/WHEEL +1 -1
- json_repair-0.25.0.dist-info/RECORD +0 -7
- {json_repair-0.25.0.dist-info → json_repair-0.25.2.dist-info}/LICENSE +0 -0
- {json_repair-0.25.0.dist-info → json_repair-0.25.2.dist-info}/top_level.txt +0 -0
json_repair/json_repair.py
CHANGED
@@ -119,40 +119,38 @@ class JSONParser:
|
|
119
119
|
def parse_json(
|
120
120
|
self,
|
121
121
|
) -> JSONReturnType:
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
self.index += 1
|
155
|
-
return self.parse_json()
|
122
|
+
while True:
|
123
|
+
char = self.get_char_at()
|
124
|
+
# This parser will ignore any basic element (string or number) that is not inside an array or object
|
125
|
+
is_in_context = len(self.context) > 0
|
126
|
+
# False means that we are at the end of the string provided
|
127
|
+
if char is False:
|
128
|
+
return ""
|
129
|
+
# <object> starts with '{'
|
130
|
+
elif char == "{":
|
131
|
+
self.index += 1
|
132
|
+
return self.parse_object()
|
133
|
+
# <array> starts with '['
|
134
|
+
elif char == "[":
|
135
|
+
self.index += 1
|
136
|
+
return self.parse_array()
|
137
|
+
# there can be an edge case in which a key is empty and at the end of an object
|
138
|
+
# like "key": }. We return an empty string here to close the object properly
|
139
|
+
elif char == "}":
|
140
|
+
self.log(
|
141
|
+
"At the end of an object we found a key with missing value, skipping",
|
142
|
+
"info",
|
143
|
+
)
|
144
|
+
return ""
|
145
|
+
# <string> starts with a quote
|
146
|
+
elif is_in_context and (char in ['"', "'", "“"] or char.isalpha()):
|
147
|
+
return self.parse_string()
|
148
|
+
# <number> starts with [0-9] or minus
|
149
|
+
elif is_in_context and (char.isdigit() or char == "-" or char == "."):
|
150
|
+
return self.parse_number()
|
151
|
+
# If everything else fails, we just ignore and move on
|
152
|
+
else:
|
153
|
+
self.index += 1
|
156
154
|
|
157
155
|
def parse_object(self) -> Dict[str, Any]:
|
158
156
|
# <object> ::= '{' [ <member> *(', ' <member>) ] '}' ; A sequence of 'members'
|
@@ -515,15 +513,15 @@ class JSONParser:
|
|
515
513
|
break
|
516
514
|
i += 1
|
517
515
|
next_c = self.get_char_at(i)
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
516
|
+
# Only if we fail to find a ':' then we know this is misplaced quote
|
517
|
+
if next_c != ":":
|
518
|
+
self.log(
|
519
|
+
"While parsing a string, we a misplaced quote that would have closed the string but has a different meaning here, ignoring it",
|
520
|
+
"info",
|
521
|
+
)
|
522
|
+
string_acc += char
|
523
|
+
self.index += 1
|
524
|
+
char = self.get_char_at()
|
527
525
|
|
528
526
|
if (
|
529
527
|
char
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: json_repair
|
3
|
-
Version: 0.25.
|
3
|
+
Version: 0.25.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
|
@@ -35,6 +35,11 @@ Requires-Python: >=3.7
|
|
35
35
|
Description-Content-Type: text/markdown
|
36
36
|
License-File: LICENSE
|
37
37
|
|
38
|
+
[](https://pypi.org/project/json-repair/)
|
39
|
+

|
40
|
+
[](https://pypi.org/project/json-repair/)
|
41
|
+
|
42
|
+
|
38
43
|
This simple package can be used to fix an invalid json string. To know all cases in which this package will work, check out the unit test.
|
39
44
|
|
40
45
|
Inspired by https://github.com/josdejong/jsonrepair
|
@@ -0,0 +1,7 @@
|
|
1
|
+
json_repair/__init__.py,sha256=IIzSm1DsCRrr8seF3UeMZXwxcq-tE3j-8d1WBxvEJvE,178
|
2
|
+
json_repair/json_repair.py,sha256=6eotLHzIoUkaePNwACuvvtQNfm9o9r5pksRNv5kv74o,30997
|
3
|
+
json_repair-0.25.2.dist-info/LICENSE,sha256=wrjQo8MhNrNCicXtMe3MHmS-fx8AmQk1ue8AQwiiFV8,1076
|
4
|
+
json_repair-0.25.2.dist-info/METADATA,sha256=FTjJyY__0i--KpI1tguLLt-jE501EkyGi4oeB6CO2zc,7863
|
5
|
+
json_repair-0.25.2.dist-info/WHEEL,sha256=mguMlWGMX-VHnMpKOjjQidIo1ssRlCFu4a4mBpz1s2M,91
|
6
|
+
json_repair-0.25.2.dist-info/top_level.txt,sha256=7-VZwZN2CgB_n0NlSLk-rEUFh8ug21lESbsblOYuZqw,12
|
7
|
+
json_repair-0.25.2.dist-info/RECORD,,
|
@@ -1,7 +0,0 @@
|
|
1
|
-
json_repair/__init__.py,sha256=IIzSm1DsCRrr8seF3UeMZXwxcq-tE3j-8d1WBxvEJvE,178
|
2
|
-
json_repair/json_repair.py,sha256=RyxtqoMopJvEwVestHDP_D6FnVkSt3bmmr1liYOQwHE,30976
|
3
|
-
json_repair-0.25.0.dist-info/LICENSE,sha256=wrjQo8MhNrNCicXtMe3MHmS-fx8AmQk1ue8AQwiiFV8,1076
|
4
|
-
json_repair-0.25.0.dist-info/METADATA,sha256=K6rBtBRbVuRQICWknDvDm3OnNq_bGrwT7K6U99PPYmg,7596
|
5
|
-
json_repair-0.25.0.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
6
|
-
json_repair-0.25.0.dist-info/top_level.txt,sha256=7-VZwZN2CgB_n0NlSLk-rEUFh8ug21lESbsblOYuZqw,12
|
7
|
-
json_repair-0.25.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|