The shell script will find all .json files that do not have .min in the filename, and then pass the file contents to the python program.
The python program will accept the json through stdin.
| import sys | |
| import re | |
| json = sys.stdin.read() | |
| try: | |
| j = eval(json) | |
| except SyntaxError: | |
| sys.stderr.write("The inputted JSON is invalid, please pipe in valid JSON") | |
| sys.exit(1) | |
| else: | |
| sys.stdout.write(re.sub(r'\s+(?=([^"]*"[^"]*")*[^"]*$)', "", str(j).replace("'", '"'))) |
| find . -maxdepth 1 -name "*.json" ! -name ".min" -exec cat {} \; | python minify.py |