Browse Source

Example working with jsonlines.

Steve Thielemann 5 years ago
parent
commit
3f853803dc
2 changed files with 29 additions and 0 deletions
  1. 28 0
      examples/json_try.py
  2. 1 0
      req.txt

+ 28 - 0
examples/json_try.py

@@ -0,0 +1,28 @@
+#!/usr/bin/env python
+
+import jsonlines
+from pprint import pprint
+
+filename = 'test.json'
+
+def make_glob():
+    d = dict()
+    for x in range(10):
+        key = "important{0}".format(x)
+        d[key] = "Yeah, {0} is very important to remember.".format(x)
+    return d
+
+print("Creating...")
+
+with jsonlines.open (filename, 'w') as writer:
+    for x in range(200):
+        writer.write(make_glob())
+
+
+print("Reading...")
+
+with jsonlines.open(filename, 'r') as reader:
+    for obj in reader:
+        pprint(obj)
+
+        

+ 1 - 0
req.txt

@@ -18,3 +18,4 @@ typed-ast==1.4.0
 zope.interface==4.6.0
 colorama==0.4.1
 pendulum==2.0.5
+jsonlines