diff options
author | B Stack <bgstack15@gmail.com> | 2021-01-18 09:51:52 -0500 |
---|---|---|
committer | B Stack <bgstack15@gmail.com> | 2021-01-18 09:51:52 -0500 |
commit | e7c98819e3b5a273b6bcb87883e6c1d15670ae19 (patch) | |
tree | 38acf0edcc3f6bd29b8b616bbfdf890098611883 /json-to-csv.py | |
download | j2c-e7c98819e3b5a273b6bcb87883e6c1d15670ae19.tar.gz j2c-e7c98819e3b5a273b6bcb87883e6c1d15670ae19.tar.bz2 j2c-e7c98819e3b5a273b6bcb87883e6c1d15670ae19.zip |
Diffstat (limited to 'json-to-csv.py')
-rwxr-xr-x | json-to-csv.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/json-to-csv.py b/json-to-csv.py new file mode 100755 index 0000000..0ae022d --- /dev/null +++ b/json-to-csv.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python3 +# File: json-to-csv.py +# Location: https://gitlab.com/bgstack15/j2c +# Author: bgstack15 +# Startdate: 2021-01-16 +# SPDX-License-Identifier: CC-BY-SA-4.0 +# Title: Json to CSV cli utility +# Purpose: Front-end logic and argument parser +# History: +# Usage: +# Reference: +# Improve: +# Dependencies: +# j2c.py in this package +# Documentation: +from j2c import * +import argparse +debug = 0 + +parser = argparse.ArgumentParser() +parser.add_argument("-d","--debug", nargs='?', default=0, type=int, choices=range(0,11),help="Set debug level.") +parser.add_argument("-i","--infile", help="Json file to convert") +parser.add_argument("-o","--outfile", help="Csv file to output") +args = parser.parse_args() + +debug = args.debug if args.debug != None else 0 +if args.infile is None: + print("Need -i infile! Aborted",file=sys.stderr) + sys.exit(1) +else: + jsonfile = args.infile + +if args.outfile is None: + outfile = "stdout" +else: + outfile = args.outfile + +convert_json_to_csv(jsonfile,outfile,debug=debug) |