json-repair 0.38.0__py3-none-any.whl → 0.39.0__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- json_repair/json_repair.py +20 -7
- {json_repair-0.38.0.dist-info → json_repair-0.39.0.dist-info}/METADATA +1 -1
- {json_repair-0.38.0.dist-info → json_repair-0.39.0.dist-info}/RECORD +7 -7
- {json_repair-0.38.0.dist-info → json_repair-0.39.0.dist-info}/LICENSE +0 -0
- {json_repair-0.38.0.dist-info → json_repair-0.39.0.dist-info}/WHEEL +0 -0
- {json_repair-0.38.0.dist-info → json_repair-0.39.0.dist-info}/entry_points.txt +0 -0
- {json_repair-0.38.0.dist-info → json_repair-0.39.0.dist-info}/top_level.txt +0 -0
json_repair/json_repair.py
CHANGED
@@ -160,7 +160,7 @@ def cli(inline_args: Optional[List[str]] = None) -> int:
|
|
160
160
|
|
161
161
|
Args:
|
162
162
|
inline_args (Optional[List[str]]): List of command-line arguments for testing purposes. Defaults to None.
|
163
|
-
- filename (str): The JSON file to repair
|
163
|
+
- filename (str): The JSON file to repair. If omitted, the JSON is read from stdin.
|
164
164
|
- -i, --inline (bool): Replace the file inline instead of returning the output to stdout.
|
165
165
|
- -o, --output TARGET (str): If specified, the output will be written to TARGET filename instead of stdout.
|
166
166
|
- --ensure_ascii (bool): Pass ensure_ascii=True to json.dumps(). Will pass False otherwise.
|
@@ -174,9 +174,15 @@ def cli(inline_args: Optional[List[str]] = None) -> int:
|
|
174
174
|
|
175
175
|
Example:
|
176
176
|
>>> cli(['example.json', '--indent', '4'])
|
177
|
+
>>> cat json.txt | json_repair
|
177
178
|
"""
|
178
179
|
parser = argparse.ArgumentParser(description="Repair and parse JSON files.")
|
179
|
-
|
180
|
+
# Make the filename argument optional; if omitted, we will read from stdin.
|
181
|
+
parser.add_argument(
|
182
|
+
"filename",
|
183
|
+
nargs="?",
|
184
|
+
help="The JSON file to repair (if omitted, reads from stdin)",
|
185
|
+
)
|
180
186
|
parser.add_argument(
|
181
187
|
"-i",
|
182
188
|
"--inline",
|
@@ -204,9 +210,12 @@ def cli(inline_args: Optional[List[str]] = None) -> int:
|
|
204
210
|
if inline_args is None: # pragma: no cover
|
205
211
|
args = parser.parse_args()
|
206
212
|
else:
|
207
|
-
args = parser.parse_args(
|
208
|
-
|
209
|
-
|
213
|
+
args = parser.parse_args(inline_args)
|
214
|
+
|
215
|
+
# Inline mode requires a filename, so error out if none was provided.
|
216
|
+
if args.inline and not args.filename: # pragma: no cover
|
217
|
+
print("Error: Inline mode requires a filename", file=sys.stderr)
|
218
|
+
sys.exit(1)
|
210
219
|
|
211
220
|
if args.inline and args.output: # pragma: no cover
|
212
221
|
print("Error: You cannot pass both --inline and --output", file=sys.stderr)
|
@@ -217,8 +226,12 @@ def cli(inline_args: Optional[List[str]] = None) -> int:
|
|
217
226
|
ensure_ascii = True
|
218
227
|
|
219
228
|
try:
|
220
|
-
|
221
|
-
|
229
|
+
# Use from_file if a filename is provided; otherwise read from stdin.
|
230
|
+
if args.filename:
|
231
|
+
result = from_file(args.filename)
|
232
|
+
else:
|
233
|
+
data = sys.stdin.read()
|
234
|
+
result = loads(data)
|
222
235
|
if args.inline or args.output:
|
223
236
|
with open(args.output or args.filename, mode="w") as fd:
|
224
237
|
json.dump(result, fd, indent=args.indent, ensure_ascii=ensure_ascii)
|
@@ -2,12 +2,12 @@ json_repair/__init__.py,sha256=c4L2kZrHvWEKfj_ODU2naliNuvU6FlFVxtF0hbLe6s8,178
|
|
2
2
|
json_repair/__main__.py,sha256=EsJb-y89uZEvGQQg1GdIDWzfDwfOMvVekKEtdguQXCM,67
|
3
3
|
json_repair/json_context.py,sha256=mm6dOyrPJ1sDskTORZSXCW7W9-5veMlUKqXQ3Hw3EG4,971
|
4
4
|
json_repair/json_parser.py,sha256=BQsH8CRy59C2176bMwVerfqbHDXfLoEC1v5frmCiv7M,39020
|
5
|
-
json_repair/json_repair.py,sha256=
|
5
|
+
json_repair/json_repair.py,sha256=k-5HRRlCqrxNmJi0u1KE3IUeL4HXqi1XZ7oAL-NFDLo,10314
|
6
6
|
json_repair/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
7
7
|
json_repair/string_file_wrapper.py,sha256=koZmdq2-Z5K7XF1bDqX6dEbNaVMJYcMTjq-aGe6NQvA,4526
|
8
|
-
json_repair-0.
|
9
|
-
json_repair-0.
|
10
|
-
json_repair-0.
|
11
|
-
json_repair-0.
|
12
|
-
json_repair-0.
|
13
|
-
json_repair-0.
|
8
|
+
json_repair-0.39.0.dist-info/LICENSE,sha256=wrjQo8MhNrNCicXtMe3MHmS-fx8AmQk1ue8AQwiiFV8,1076
|
9
|
+
json_repair-0.39.0.dist-info/METADATA,sha256=cArvqcMBL9FVCwnJGtsaeF7lXWjOFWG3_1OueGjOiRs,11794
|
10
|
+
json_repair-0.39.0.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
11
|
+
json_repair-0.39.0.dist-info/entry_points.txt,sha256=SNfge3zPSP-ASqriYU9r3NAPaXdseYr7ciPMKdV2uSw,57
|
12
|
+
json_repair-0.39.0.dist-info/top_level.txt,sha256=7-VZwZN2CgB_n0NlSLk-rEUFh8ug21lESbsblOYuZqw,12
|
13
|
+
json_repair-0.39.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|