The behavior of json.dumps is different when the indent option is specified between python2.7 and python3.6. In python2, there is one space before the line feed code, but in python3 it is not.
import json
json.dumps({"name": 'aaa', "age": 21}, sort_keys=True, indent=2)
python2.7.8
'{\n "age": 21, \n "name": "aaa"\n}'
python3.6.0
> '{\n "age": 21,\n "name": "aaa"\n}'
Issue 16333: Trailing whitespace in json dump when using indent - Python tracker
Add separators = (',',':')
to the options in json.dumps.
import json
json.dumps({"name": 'aaa', "age": 21}, sort_keys=True, indent=2, separators=(',', ': '))