Skip to content

Instantly share code, notes, and snippets.

@phoenleo
Created January 14, 2016 09:04
Show Gist options
  • Select an option

  • Save phoenleo/5a0a2f7e22528e5002d8 to your computer and use it in GitHub Desktop.

Select an option

Save phoenleo/5a0a2f7e22528e5002d8 to your computer and use it in GitHub Desktop.
Convert Localization CSV to JSON
import csv
import json
import collections
csvfile = open('file.csv', 'r')
def isKeyEmptyOrComment (stringKey):
if not stringKey: return True
if stringKey[0] == "@": return True
return False
reader = csv.reader(csvfile)
ncol = len(next(reader))
csvfile.seek(0)
headers = reader.next()
csvfile.seek(0)
next(reader)
for col in range(1, ncol):
mydict = collections.OrderedDict()
jsonfile = open(headers[col] +'.json', 'w')
for rows in reader:
if isKeyEmptyOrComment(rows[0]): continue
mydict[rows[0]] = rows[col]
json.dump(mydict, jsonfile)
csvfile.seek(0)
next(reader)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment