-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconverter.py
More file actions
30 lines (25 loc) · 1.17 KB
/
converter.py
File metadata and controls
30 lines (25 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env python3
"""
JSON to CSV Converter
Converts JSON files to CSV format using Click for command-line interface.
Supports both individual files and batch processing of folders.
"""
from pathlib import Path
import click
from jsonconverter import JSONconvert
@click.command()
@click.argument('input_path', type=click.Path(exists=True, path_type=Path))
@click.option('--output-dir', '-o', type=click.Path(path_type=Path), help='Output directory output files (default: same as input)')
@click.option('--output-format', default='csv', help='Output file format (default: csv)')
@click.option('--recursive', '-r', is_flag=True, help='Process JSON files in subdirectories recursively')
@click.option('--verbose', '-v', is_flag=True, help='Verbose output')
def convert(input_path: Path, recursive: bool, output_dir: Path, output_format: str, verbose: bool):
"""
Convert JSON files to CSV format.
INPUT_PATH can be either a single JSON file or a directory containing JSON files.
"""
converter = JSONconvert(verbose)
exported_files = converter.convert(input_path, output_dir, output_format, recursive)
print(exported_files)
if __name__ == '__main__':
convert()