json-repair 0.29.0__py3-none-any.whl → 0.29.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.
@@ -760,7 +760,7 @@ def from_file(
760
760
  return jsonobj
761
761
 
762
762
 
763
- def cli(): # pragma: no cover
763
+ def cli(inline_args: Optional[List[str]] = None) -> int:
764
764
  parser = argparse.ArgumentParser(description="Repair and parse JSON files.")
765
765
  parser.add_argument("filename", help="The JSON file to repair")
766
766
  parser.add_argument(
@@ -769,10 +769,16 @@ def cli(): # pragma: no cover
769
769
  action="store_true",
770
770
  help="Replace the file inline instead of returning the output to stdout",
771
771
  )
772
+ parser.add_argument(
773
+ "-o",
774
+ "--output",
775
+ metavar="TARGET",
776
+ help="If specified, the output will be written to TARGET filename instead of stdout",
777
+ )
772
778
  parser.add_argument(
773
779
  "--ensure_ascii",
774
780
  action="store_true",
775
- help="Pass the ensure_ascii parameter to json.dumps()",
781
+ help="Pass ensure_ascii=True to json.dumps()",
776
782
  )
777
783
  parser.add_argument(
778
784
  "--indent",
@@ -781,24 +787,36 @@ def cli(): # pragma: no cover
781
787
  help="Number of spaces for indentation (Default 2)",
782
788
  )
783
789
 
784
- args = parser.parse_args()
790
+ if inline_args is None: # pragma: no cover
791
+ args = parser.parse_args()
792
+ else:
793
+ args = parser.parse_args(
794
+ inline_args
795
+ ) # This is needed so this function is testable
796
+
797
+ if args.inline and args.output: # pragma: no cover
798
+ print("Error: You cannot pass both --inline and --output", file=sys.stderr)
799
+ sys.exit(1)
785
800
 
786
801
  ensure_ascii = False
787
802
  if args.ensure_ascii:
788
803
  ensure_ascii = True
804
+
789
805
  try:
790
806
  result = from_file(args.filename)
791
807
 
792
- if args.inline:
793
- fd = open(args.filename, mode="w")
808
+ if args.inline or args.output:
809
+ fd = open(args.output or args.filename, mode="w")
794
810
  json.dump(result, fd, indent=args.indent, ensure_ascii=ensure_ascii)
795
811
  fd.close()
796
812
  else:
797
813
  print(json.dumps(result, indent=args.indent, ensure_ascii=ensure_ascii))
798
- except Exception as e:
814
+ except Exception as e: # pragma: no cover
799
815
  print(f"Error: {str(e)}", file=sys.stderr)
800
816
  sys.exit(1)
801
817
 
818
+ return 0 # Success
819
+
802
820
 
803
821
  if __name__ == "__main__": # pragma: no cover
804
- cli()
822
+ sys.exit(cli())
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: json_repair
3
- Version: 0.29.0
3
+ Version: 0.29.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
@@ -156,24 +156,24 @@ Install the library for command-line with:
156
156
  ```
157
157
  pipx install json-repair
158
158
  ```
159
- then run
159
+ to know all options available:
160
160
  ```
161
161
  $ json_repair -h
162
-
163
- usage: json_repair [-h] [-i] [--ensure_ascii] [--indent INDENT] filename
162
+ usage: json_repair [-h] [-i] [-o TARGET] [--ensure_ascii] [--indent INDENT] filename
164
163
 
165
164
  Repair and parse JSON files.
166
165
 
167
166
  positional arguments:
168
- filename The JSON file to repair
167
+ filename The JSON file to repair
169
168
 
170
169
  options:
171
- -h, --help show this help message and exit
172
- -i, --inline Replace the file inline instead of returning the output to stdout
173
- --ensure_ascii Pass the ensure_ascii parameter to json.dumps()
174
- --indent INDENT Number of spaces for indentation (Default 2)
170
+ -h, --help show this help message and exit
171
+ -i, --inline Replace the file inline instead of returning the output to stdout
172
+ -o TARGET, --output TARGET
173
+ If specified, the output will be written to TARGET filename instead of stdout
174
+ --ensure_ascii Pass ensure_ascii=True to json.dumps()
175
+ --indent INDENT Number of spaces for indentation (Default 2)
175
176
  ```
176
- to learn how to use it
177
177
 
178
178
  ## Adding to requirements
179
179
  **Please pin this library only on the major version!**
@@ -0,0 +1,10 @@
1
+ json_repair/__init__.py,sha256=IIzSm1DsCRrr8seF3UeMZXwxcq-tE3j-8d1WBxvEJvE,178
2
+ json_repair/__main__.py,sha256=EsJb-y89uZEvGQQg1GdIDWzfDwfOMvVekKEtdguQXCM,67
3
+ json_repair/json_repair.py,sha256=amzSIOX_wR22QCheozEzsPLA09RRc8AybBUaiIIJagI,34164
4
+ json_repair/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ json_repair-0.29.1.dist-info/LICENSE,sha256=wrjQo8MhNrNCicXtMe3MHmS-fx8AmQk1ue8AQwiiFV8,1076
6
+ json_repair-0.29.1.dist-info/METADATA,sha256=q2kI12fNuayrEkqqDtVWKmagimcSgAKPHdanuQwMAtI,9787
7
+ json_repair-0.29.1.dist-info/WHEEL,sha256=cVxcB9AmuTcXqmwrtPhNK88dr7IR_b6qagTj0UvIEbY,91
8
+ json_repair-0.29.1.dist-info/entry_points.txt,sha256=SNfge3zPSP-ASqriYU9r3NAPaXdseYr7ciPMKdV2uSw,57
9
+ json_repair-0.29.1.dist-info/top_level.txt,sha256=7-VZwZN2CgB_n0NlSLk-rEUFh8ug21lESbsblOYuZqw,12
10
+ json_repair-0.29.1.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (74.1.1)
2
+ Generator: setuptools (74.1.2)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,10 +0,0 @@
1
- json_repair/__init__.py,sha256=IIzSm1DsCRrr8seF3UeMZXwxcq-tE3j-8d1WBxvEJvE,178
2
- json_repair/__main__.py,sha256=EsJb-y89uZEvGQQg1GdIDWzfDwfOMvVekKEtdguQXCM,67
3
- json_repair/json_repair.py,sha256=hltJ3Qa4qFbUD3mVKkYvFWksnCcIZqx8zamKfBpjeNs,33538
4
- json_repair/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
- json_repair-0.29.0.dist-info/LICENSE,sha256=wrjQo8MhNrNCicXtMe3MHmS-fx8AmQk1ue8AQwiiFV8,1076
6
- json_repair-0.29.0.dist-info/METADATA,sha256=yh0EJo-I1u0R6X-Gq9ETz0WbgmuGIhzR7Icw9W4Kee0,9630
7
- json_repair-0.29.0.dist-info/WHEEL,sha256=uCRv0ZEik_232NlR4YDw4Pv3Ajt5bKvMH13NUU7hFuI,91
8
- json_repair-0.29.0.dist-info/entry_points.txt,sha256=SNfge3zPSP-ASqriYU9r3NAPaXdseYr7ciPMKdV2uSw,57
9
- json_repair-0.29.0.dist-info/top_level.txt,sha256=7-VZwZN2CgB_n0NlSLk-rEUFh8ug21lESbsblOYuZqw,12
10
- json_repair-0.29.0.dist-info/RECORD,,