From e7c98819e3b5a273b6bcb87883e6c1d15670ae19 Mon Sep 17 00:00:00 2001 From: B Stack Date: Mon, 18 Jan 2021 09:51:52 -0500 Subject: initial commit --- json-to-csv.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100755 json-to-csv.py (limited to 'json-to-csv.py') 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) -- cgit