Skip to content

Instantly share code, notes, and snippets.

@Aareon
Last active January 2, 2016 21:52
Show Gist options
  • Save Aareon/95118516b7db4f88939c to your computer and use it in GitHub Desktop.
Save Aareon/95118516b7db4f88939c to your computer and use it in GitHub Desktop.
/util/parse.py
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