Advertisement
rfmonk

json_sort_keys.py

Feb 19th, 2014
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.37 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3.  
  4. import json
  5.  
  6. data = [{'a': 'A', 'b': (2, 4), 'c': 3.0}]
  7. print 'DATA:', repr(data)
  8.  
  9. unsorted = json.dumps(data)
  10. print 'JSON:', json.dumps(data)
  11. print 'SORT:', json.dumps(data, sort_keys=True)
  12.  
  13. first = json.dumps(data, sort_keys=True)
  14. second = json.dumps(data, sort_keys=True)
  15.  
  16. print 'UNSORTED MATCH:', unsorted == first
  17. print 'SORTED MATCH:', first == second
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement