80_json.py 1003 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. a = {
  2. 'a': 1,
  3. 'b': 2,
  4. 'c': None,
  5. 'd': [1, 2, 3],
  6. 'e': {
  7. 'a': 1,
  8. 'b': 2,
  9. 'c': None,
  10. 'd': [1, 2, 3],
  11. },
  12. "f": 'This is a string',
  13. 'g': [True, False, None],
  14. 'h': False
  15. }
  16. import json
  17. _j = json.dumps(a)
  18. _a = json.loads(_j)
  19. for k, v in a.items():
  20. assert a[k] == _a[k]
  21. for k, v in _a.items():
  22. assert a[k] == _a[k]
  23. b = [1, 2, True, None, False]
  24. _j = json.dumps(b)
  25. _b = json.loads(_j)
  26. assert b == _b
  27. c = 1.0
  28. _j = json.dumps(c)
  29. _c = json.loads(_j)
  30. assert c == _c
  31. d = True
  32. _j = json.dumps(d)
  33. _d = json.loads(_j)
  34. assert d == _d
  35. assert repr((1,)) == '(1,)'
  36. assert repr((1, 2, 3)) == '(1, 2, 3)'
  37. assert repr(tuple()) == '()'
  38. assert json.dumps((1,)) == '[1]'
  39. assert json.dumps((1, 2, 3)) == '[1, 2, 3]'
  40. assert json.dumps(tuple()) == '[]'
  41. assert repr([]) == '[]'
  42. assert repr([1, 2, 3]) == '[1, 2, 3]'
  43. assert repr([1]) == '[1]'
  44. assert json.dumps([]) == '[]'
  45. assert json.dumps([1, 2, 3]) == '[1, 2, 3]'
  46. assert json.dumps([1]) == '[1]'