Guest User

Untitled

a guest
Feb 24th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. {
  2. "A": [
  3. {
  4. "B": 0,
  5. "C": 1
  6. }
  7. ],
  8. "D": [
  9. {
  10. "E": 2,
  11. "F": 4}
  12. ]
  13. }
  14.  
  15. import json
  16. from pathlib import Path
  17. path = Path('newtest.json')
  18. data = json.loads(path.read_text(encoding='utf-8'))
  19. data['A'].append({'B':50,'C':50})
  20. path.write_text(json.dumps(data,sort_keys=True, indent=4, separators=(',', ': ')), encoding='utf-8')
  21.  
  22. {
  23. "A": [
  24. {
  25. "B": 0,
  26. "C": 1
  27. },
  28. {
  29. "B": 50,
  30. "C": 50
  31. }
  32. ],
  33. "D": [
  34. {
  35. "E": 2,
  36. "F": 4
  37. }
  38. ]
  39. }
Add Comment
Please, Sign In to add comment