def sortedJSONDumpS(obj):
 itemStrs = []
 if isinstance(obj, dict):
  items = obj.items()
  items.sort()
  for (key, value) in items:
   itemStrs.append(('%s: %s' % (json.dumps(key), sortedJSONDumpS(value))))
  return ('{%s}' % ', '.join(itemStrs))
 elif hasattr(obj, '__iter__'):
  for val in obj:
   itemStrs.append(sortedJSONDumpS(val))
  return ('[%s]' % ', '.join(itemStrs))
 else:
  return json.dumps(obj)

def sortedJSONDumpS ( obj ) : itemStrs = [ ] if isinstance ( obj , dict ) : items = obj . items ( ) items . sort ( ) for ( key , value ) in items : itemStrs . append ( ( '%s: %s' % ( json . dumps ( key ) , sortedJSONDumpS ( value ) ) ) ) return ( '{%s}' % ', ' . join ( itemStrs ) ) elif hasattr ( obj , '__iter__' ) : for val in obj : itemStrs . append ( sortedJSONDumpS ( val ) ) return ( '[%s]' % ', ' . join ( itemStrs ) ) else : return json . dumps ( obj )
return a json representation of obj with sorted keys on any embedded dicts .