#!/usr/bin/env python3 import argparse from pathlib import Path commentSymbol = "//" parser = argparse.ArgumentParser(description="Remove comment from json.") parser.add_argument("input", help="input file path") parser.add_argument("output", help="output file path") args = parser.parse_args() if args.input == args.output: print("Error : output file must not be the same name as input file...") else: try: inputFile = open(args.input, mode='r', encoding='utf-8') outputFilePath = Path(args.output) outputFilePath.touch(exist_ok=True) outputFile = open(outputFilePath, 'w', encoding='utf-8') for line in inputFile: if commentSymbol in line: continue if not line.isspace(): outputFile.write(line) finally: inputFile.close() outputFile.close()