Last active
September 14, 2016 14:23
-
-
Save guyarad/d80b9d5652a6616e1c3138b6a86310c4 to your computer and use it in GitHub Desktop.
Text filter intended to be used with TextWrangler application (Mac OSX) in order to reformat (tidy-up) a JSON file.
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/python | |
# | |
# Script was modified from: | |
# https://steveswinsburg.wordpress.com/2014/09/26/textwrangler-filters-to-tidy-xml-and-tidy-json/ | |
# Modified by Guy Arad, and can be found in: | |
# https://gist.github.com/guyarad/d80b9d5652a6616e1c3138b6a86310c4 | |
# | |
# Installation: | |
# Copy to "~/Library/Application Support/TextWrangler/Text Filters" | |
# | |
# Usage: | |
# Within TextWrangler, Menu -> Text -> Apply Text Filter -> [Filter Name] | |
# | |
import fileinput | |
import json | |
import itertools | |
input1, input2 = itertools.tee(fileinput.input()) | |
try: | |
print json.dumps( | |
json.loads(''.join(line.strip() for line in input1)), | |
sort_keys=True, | |
indent=2) | |
finally: | |
print ''.join(input2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment