Created
May 27, 2015 07:04
-
-
Save vojtatranta/474949cb54152d6ec61a to your computer and use it in GitHub Desktop.
anything to JSON in python
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
def jsonize(self, data_dict): | |
dict_string = {} | |
for key, value in data_dict.items(): | |
if isinstance(value, QuerySet): | |
dict_string[key] = serializers.serialize('json', value) | |
else: | |
dict_string[key] = json.dumps(value) | |
json_str = '{' | |
for key, value in dict_string.items(): | |
json_str += '"%s":%s,' % (key, value) | |
json_str = json_str[:-1] + '}' | |
return json_str |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment