使用 separators 参数来更改默认分隔符

  1. import json
  2.  
  3. x = {
  4. "name": "Bill",
  5. "age": 63,
  6. "married": True,
  7. "divorced": False,
  8. "children": ("Jennifer","Rory","Phoebe"),
  9. "pets": None,
  10. "cars": [
  11. {"model": "Porsche", "mpg": 38.2},
  12. {"model": "BMW M5", "mpg": 26.9}
  13. ]
  14. }
  15.  
  16. # use . and a space to separate objects, and a space, a = and a space to separate keys from their values:
  17. print(json.dumps(x, indent=4, separators=(". ", " = ")))