Skip to main content

StreamJSON

PyPI - Python Version PyPI PyPI - License

tests

Write objects or arrays to a JSON file using a stream. Useful for when you don't want to read large amounts of data in memory, for example when you need to save large amounts of data from a database to a single JSON file.

Read objects from a JSON file using a stream. Does not require loading the whole JSON file in memory.

Install

pip install streamjson

How to write to JSON file

Fetch data from a database or anywhere else and send to a JSON file. The send function takes in a dictionary or a list. A new file with the given name will be created, the root of the JSON file is an array by default.

from streamjson import StreamJSONWriter

persons = [{'id': '0001', 'first_name': 'John', 'last_name': 'Doe'},
           {'id': '0002', 'first_name': 'Jane', 'last_name': 'Doe'}]

with StreamJSONWriter('persons.json', indent=2) as writer:
    for person in persons:
        writer.send(person)

persons.json:

[
  {
    "id": "0001",
    "first_name": "John",
    "last_name": "Doe"
  },
  {
    "id": "0002",
    "first_name": "Jane",
    "last_name": "Doe"
  }
]

How to read from JSON file

The reader will stream each object from the JSON file.

from streamjson import StreamJSONReader

with StreamJSONReader('persons.json') as reader:
    for obj in reader.find():
        print(obj)

Metadata

Release files for streamjson 1.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for streamjson 1.0.4
File Size Uploaded
streamjson-1.0.4.tar.gz 5.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for streamjson 1.0.4
File Interpreter ABI Platform
streamjson-1.0.4-py3-none-any.whl Python 3 none any Details

Total release size: 12.3 kB

Release files / streamjson-1.0.4.tar.gz

Download URL streamjson-1.0.4.tar.gz
Size 5.6 kB
Tags Source
SHA-256 checksum
How to use checksums
be80d88fb925349f821e9876546d3d81361d984253890cd081898ee7eeadd3eb
BLAKE2b-256 checksum
How to use checksums
124a950de5709ed1289fe86c6616e1c8dcf61321ccdd917e58aeffebc13be52b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release files / streamjson-1.0.4-py3-none-any.whl

Download URL streamjson-1.0.4-py3-none-any.whl
Size 6.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cffe1bbf6560432d55ca40dd3524a1cea95b7a67a375b5c24e6956f8ad58f49d
BLAKE2b-256 checksum
How to use checksums
f949e5af4a6fa0a6f3fc99a78a90dfbc7c5ac89815d0d1adecd656c3a635721e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release history Release notifications | RSS feed

This release

1.0.4 This release

2 release files

1.0.3

2 release files

1.0.2

1 release file

1.0.0

1 release file

0.0.4

1 release file

0.0.3

1 release file

0.0.2

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page