1
0

73_json_indent.py 815 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import json
  2. # test empty
  3. assert json.dumps({}, indent=2) == '{}'
  4. assert json.dumps([], indent=2) == '[]'
  5. assert json.dumps(object().__dict__, indent=2) == '{}'
  6. assert json.dumps([1, 2, [3, 4], 5], indent=2) == '[\n 1,\n 2,\n [\n 3,\n 4\n ],\n 5\n]'
  7. a = {
  8. 'a': 1,
  9. 'b': 2,
  10. 'c': None,
  11. 'd': [1, 2, 3],
  12. 'e': {
  13. 'a': 100,
  14. 'b': 2.5,
  15. 'c': None,
  16. 'd': [142, 2785, 39767],
  17. },
  18. "f": 'This is a string',
  19. 'g': [True, False, None],
  20. 'h': False
  21. }
  22. assert json.dumps(a, indent=2) == '''{
  23. "a": 1,
  24. "b": 2,
  25. "c": null,
  26. "d": [
  27. 1,
  28. 2,
  29. 3
  30. ],
  31. "e": {
  32. "a": 100,
  33. "b": 2.5,
  34. "c": null,
  35. "d": [
  36. 142,
  37. 2785,
  38. 39767
  39. ]
  40. },
  41. "f": "This is a string",
  42. "g": [
  43. true,
  44. false,
  45. null
  46. ],
  47. "h": false
  48. }'''