Skip to content

Instantly share code, notes, and snippets.

@SamuraiT
Created July 13, 2014 06:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SamuraiT/ccb31b2883144838c4b5 to your computer and use it in GitHub Desktop.
Save SamuraiT/ccb31b2883144838c4b5 to your computer and use it in GitHub Desktop.
json converter example
#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())
@SamuraiT
Copy link
Author

Output:

{'title': 'pypy', 'python_id': 4, 'spam': 'spam'}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment