streamjson


Namestreamjson JSON
Version 1.0.2 PyPI version JSON
download
home_pagehttps://github.com/zaironjacobs/streamjson
SummarySend objects or arrays to a JSON file using a stream. Read objects from a JSON file using a stream.
upload_time2022-12-14 10:40:59
maintainer
docs_urlNone
authorZairon Jacobs
requires_python>=3
licenseMIT
keywords json stream write file read objects arrays
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            StreamJSON
=================
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/streamjson?color=blue)](https://pypi.python.org/pypi/streamjson)
[![PyPI](https://img.shields.io/pypi/v/streamjson?color=blue)](https://pypi.python.org/pypi/streamjson)
[![PyPI - Status](https://img.shields.io/pypi/status/streamjson)](https://pypi.python.org/pypi/streamjson)
[![PyPI - License](https://img.shields.io/pypi/l/streamjson)](https://pypi.python.org/pypi/streamjson)

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

To install:

```console
pip install streamjson
```

To upgrade:

```console
pip install streamjson --upgrade
```

## 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.

```Python
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:

```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.

```Python
from streamjson import StreamJSONReader

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

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/zaironjacobs/streamjson",
    "name": "streamjson",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3",
    "maintainer_email": "",
    "keywords": "json,stream,write,file,read,objects,arrays",
    "author": "Zairon Jacobs",
    "author_email": "zaironjacobs@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/13/df/f1a19b99526926c6952be8184b1324655ab85e4ee03bf3e2e88f9c5449e3/streamjson-1.0.2.tar.gz",
    "platform": null,
    "description": "StreamJSON\r\n=================\r\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/streamjson?color=blue)](https://pypi.python.org/pypi/streamjson)\r\n[![PyPI](https://img.shields.io/pypi/v/streamjson?color=blue)](https://pypi.python.org/pypi/streamjson)\r\n[![PyPI - Status](https://img.shields.io/pypi/status/streamjson)](https://pypi.python.org/pypi/streamjson)\r\n[![PyPI - License](https://img.shields.io/pypi/l/streamjson)](https://pypi.python.org/pypi/streamjson)\r\n\r\nWrite objects or arrays to a JSON file using a stream. Useful for when you don't want to read large amounts of data in\r\nmemory, for example when you need to save large amounts of data from a database to a single JSON file.\r\n\r\nRead objects from a JSON file using a stream. Does not require loading the whole JSON file in memory.\r\n\r\n## Install\r\n\r\nTo install:\r\n\r\n```console\r\npip install streamjson\r\n```\r\n\r\nTo upgrade:\r\n\r\n```console\r\npip install streamjson --upgrade\r\n```\r\n\r\n## How to write to JSON file\r\n\r\nFetch data from a database or anywhere else and send to a JSON file. The send function takes in a dictionary or a list.\r\nA new file with the given name will be created, the root of the JSON file is an array by default.\r\n\r\n```Python\r\nfrom streamjson import StreamJSONWriter\r\n\r\npersons = [{'id': '0001', 'first_name': 'John', 'last_name': 'Doe'},\r\n           {'id': '0002', 'first_name': 'Jane', 'last_name': 'Doe'}]\r\n\r\nwith StreamJSONWriter('persons.json', indent=2) as writer:\r\n    for person in persons:\r\n        writer.send(person)\r\n```\r\n\r\npersons.json:\r\n\r\n```JSON\r\n[\r\n  {\r\n    \"id\": \"0001\",\r\n    \"first_name\": \"John\",\r\n    \"last_name\": \"Doe\"\r\n  },\r\n  {\r\n    \"id\": \"0002\",\r\n    \"first_name\": \"Jane\",\r\n    \"last_name\": \"Doe\"\r\n  }\r\n]\r\n```\r\n\r\n## How to read from JSON file\r\n\r\nThe reader will stream each object from the JSON file.\r\n\r\n```Python\r\nfrom streamjson import StreamJSONReader\r\n\r\nwith StreamJSONReader('persons.json') as reader:\r\n    for obj in reader.find():\r\n        print(obj)\r\n```\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Send objects or arrays to a JSON file using a stream. Read objects from a JSON file using a stream.",
    "version": "1.0.2",
    "split_keywords": [
        "json",
        "stream",
        "write",
        "file",
        "read",
        "objects",
        "arrays"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "e2df9fcd3ff4eaa8299b8ab79bdfb0e8",
                "sha256": "f0749a68efdeeaf3b0053652bee73c4d17f09ef7b3658e7626b1da175498e40b"
            },
            "downloads": -1,
            "filename": "streamjson-1.0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "e2df9fcd3ff4eaa8299b8ab79bdfb0e8",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3",
            "size": 6272,
            "upload_time": "2022-12-14T10:40:59",
            "upload_time_iso_8601": "2022-12-14T10:40:59.758825Z",
            "url": "https://files.pythonhosted.org/packages/13/df/f1a19b99526926c6952be8184b1324655ab85e4ee03bf3e2e88f9c5449e3/streamjson-1.0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-12-14 10:40:59",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "zaironjacobs",
    "github_project": "streamjson",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "streamjson"
}
        
Elapsed time: 0.02702s