diff options
author | Bob Ippolito <bob@redivi.com> | 2018-09-06 11:48:37 -0700 |
---|---|---|
committer | Bob Ippolito <bob@redivi.com> | 2018-09-06 14:49:59 -0700 |
commit | 26524a0d907dda3fee69055026922876b309f8f3 (patch) | |
tree | d721c7bdae843ab4d7782bbf30ccb79f22eb8ab4 /simplejson | |
parent | ee25b0c7faeb072e2dd5bc3925bd8dc6fbb04d93 (diff) | |
download | simplejson-26524a0d907dda3fee69055026922876b309f8f3.tar.gz |
Prep for v3.16.1 and add JSON lines examplejson-lines-example
Diffstat (limited to 'simplejson')
-rw-r--r-- | simplejson/__init__.py | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/simplejson/__init__.py b/simplejson/__init__.py index 0556a7a..9d9b737 100644 --- a/simplejson/__init__.py +++ b/simplejson/__init__.py @@ -87,7 +87,6 @@ Specializing JSON object encoding:: >>> ''.join(json.JSONEncoder(default=encode_complex).iterencode(2 + 1j)) '[2.0, 1.0]' - Using simplejson.tool from the shell to validate and pretty-print:: $ echo '{"json":"obj"}' | python -m simplejson.tool @@ -96,9 +95,30 @@ Using simplejson.tool from the shell to validate and pretty-print:: } $ echo '{ 1.2:3.4}' | python -m simplejson.tool Expecting property name: line 1 column 3 (char 2) + +Parsing multiple documents serialized as JSON lines (newline-delimited JSON):: + + >>> import simplejson as json + >>> def loads_lines(docs): + ... for doc in docs.splitlines(): + ... yield json.loads(doc) + ... + >>> sum(doc["count"] for doc in loads_lines('{"count":1}\n{"count":2}\n{"count":3}\n')) + 6 + +Serializing multiple objects to JSON lines (newline-delimited JSON):: + + >>> import simplejson as json + >>> def dumps_lines(objs): + ... for obj in objs: + ... yield json.dumps(obj, separators=(',',':')) + '\n' + ... + >>> ''.join(dumps_lines([{'count': 1}, {'count': 2}, {'count': 3}])) + '{"count":1}\n{"count":2}\n{"count":3}\n' + """ from __future__ import absolute_import -__version__ = '3.16.0' +__version__ = '3.16.1' __all__ = [ 'dump', 'dumps', 'load', 'loads', 'JSONDecoder', 'JSONDecodeError', 'JSONEncoder', |