Last active
January 2, 2016 21:52
-
-
Save Aareon/95118516b7db4f88939c to your computer and use it in GitHub Desktop.
/util/parse.py
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
import re, json, codecs | |
def parse_json(filename): | |
with open(filename, 'r+') as f: | |
comment_re = re.compile('(^)?[^\S\n]*/(?:\*(.*?)\*/[^\S\n]*|/[^\n]*)($)?', re.DOTALL | re.MULTILINE) | |
content = f.read() | |
match = comment_re.search(content) | |
while match: | |
content = content[:match.start()] + content[match.end():] | |
match = comment_re.search(content) | |
global f, contents, data | |
reader = codecs.getreader("utf-8") | |
contents = json.load(content).decode("utf-8") | |
parse_json.data = contents["data"][0] | |
return() | |
if 'data' not in content: | |
# Backwards compatible with old config.json files | |
contents = {'data': [contents]} | |
data = contents["data"][0] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment