json_try.py 520 B

12345678910111213141516171819202122232425262728
  1. #!/usr/bin/env python
  2. import jsonlines
  3. from pprint import pprint
  4. filename = 'test.json'
  5. def make_glob():
  6. d = dict()
  7. for x in range(10):
  8. key = "important{0}".format(x)
  9. d[key] = "Yeah, {0} is very important to remember.".format(x)
  10. return d
  11. print("Creating...")
  12. with jsonlines.open (filename, 'w') as writer:
  13. for x in range(200):
  14. writer.write(make_glob())
  15. print("Reading...")
  16. with jsonlines.open(filename, 'r') as reader:
  17. for obj in reader:
  18. pprint(obj)