Created
July 13, 2014 06:23
-
-
Save SamuraiT/ccb31b2883144838c4b5 to your computer and use it in GitHub Desktop.
json converter example
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 json | |
#dic = json.loads(json_data) | |
dic = {'title':'pypy', 'egg':'spam', 'id':'4'} | |
_map = {'title': | |
{'name':'title', | |
'func':lambda val:str(val)}, | |
'egg': | |
{'name':'spam', | |
'func':lambda val:str(val)}, | |
'id': | |
{'name':'python_id', | |
'func':lambda val:int(val)} | |
} | |
def main(): | |
d = {} | |
for key, val in dic.items(): | |
d[_map[key]['name']] = _map[key]['func'](val) | |
return d | |
if __name__ == '__main__': | |
print(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output: