aboutsummaryrefslogtreecommitdiff
path: root/json-to-csv.py
diff options
context:
space:
mode:
authorB Stack <bgstack15@gmail.com>2021-01-18 09:51:52 -0500
committerB Stack <bgstack15@gmail.com>2021-01-18 09:51:52 -0500
commite7c98819e3b5a273b6bcb87883e6c1d15670ae19 (patch)
tree38acf0edcc3f6bd29b8b616bbfdf890098611883 /json-to-csv.py
downloadj2c-master.tar.gz
j2c-master.tar.bz2
j2c-master.zip
initial commitHEADmaster
Diffstat (limited to 'json-to-csv.py')
-rwxr-xr-xjson-to-csv.py38
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)
bgstack15