Is there any way to have python's json.dumps(<val>)
output in minified form? (i.e. get rid of extraneous spaces around commas, colons etc.)
Is there any way to have python's json.dumps(<val>)
output in minified form? (i.e. get rid of extraneous spaces around commas, colons etc.)
You should set the separators
parameter:
>>> json.dumps([1, 2, 3, {'4': 5, '6': 7}], separators=(',', ':'))
'[1,2,3,{"4":5,"6":7}]'
From the docs:
If specified, separators should be an
(item_separator, key_separator)
tuple. The default is(', ', ': ')
if indent isNone
and(',', ': ')
otherwise. To get the most compact JSON representation, you should specify(',', ':')
to eliminate whitespace.