Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python - json without whitespaces

I just realized that json.dumps() adds spaces in the JSON object

e.g.

{'duration': '02:55', 'name': 'flower', 'chg': 0} 

how can remove the spaces in order to make the JSON more compact and save bytes to be sent via HTTP?

such as:

{'duration':'02:55','name':'flower','chg':0} 
like image 947
Daniele B Avatar asked May 01 '13 01:05

Daniele B


1 Answers

json.dumps(separators=(',', ':')) 
like image 110
donghyun208 Avatar answered Sep 18 '22 17:09

donghyun208