Last active
February 28, 2023 22:35
-
-
Save CSaratakij/d2831fc8818b2276e2decb68a9764622 to your computer and use it in GitHub Desktop.
Json comment remover '//'
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
python remover.py input.json output.json |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment