@@ -14,32 +14,22 @@ def to_json(model):
1414 if isinstance (value , list ):
1515 for i in value :
1616 if not isinstance (i , (list , str , bool )):
17- if attr not in dct .keys ():
18- dct [attr ] = [to_json (i )]
19- else :
20- dct [attr ].append (to_json (i ))
17+ dct [attr ] = [to_json (i )] if attr not in dct .keys () else dct [attr ].append (to_json (i ))
2118 continue
22- if attr not in dct .keys ():
23- dct [attr ] = [to_json (i )]
24- else :
25- dct [attr ].append (to_json (i ))
19+
20+ dct [attr ] = [to_json (i )] if attr not in dct .keys () else dct [attr ].append (to_json (i ))
21+
2622 continue
2723
2824 # if it is an object attribute
2925 if not isinstance (value , (list , str , bool )):
30- if attr not in dct .keys ():
31- dct [attr ] = [to_json (value )]
32- else :
33- dct [attr ].append (to_json (value ))
26+ dct [attr ] = [to_json (value )] if attr not in dct .keys () else dct [attr ].append (to_json (value ))
3427 continue
3528
3629 # just a bool, string or int now so can safely add to dict
37- if attr not in dct .keys ():
38- dct [attr ] = [to_json (value )]
39- else :
40- dct [attr ].append (to_json (value ))
30+ dct [attr ] = [to_json (value )] if attr not in dct .keys () else dct [attr ].append (to_json (value ))
4131
42- return json .dumps (dct , separators = (',' , ':' ), ensure_ascii = True )
32+ return json .loads (dct , separators = (',' , ':' ), ensure_ascii = True )
4333
4434
4535
0 commit comments