json-dt-serializer


Namejson-dt-serializer JSON
Version 1.0.1 PyPI version JSON
download
home_pageNone
SummaryJSON, but with datetime and timestamp support
upload_time2024-05-26 16:55:05
maintainerNone
docs_urlNone
authorKen Kinder
requires_python<4.0,>=3.9
licenseLICENSE.txt
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # dtjson: json, but with datetime and timespan support

dtjson builds on regular Json, but adds support for timespan and datetime objects in Python. It does this by looking for `"__type__": "datetime"` or `"__type__": "timedelta"` in the keys, with `isoformat' and `seconds` respectively.

Example Usage::

```python
>>> import dtjson
>>> import datetime
>>> serialized = dtjson.dumps(['foo', {'bar': ('baz', None, 1.0, 2), 'spam': datetime.datetime.now()}])
>>> print(serialized)
'["foo", {"bar": ["baz", null, 1.0, 2], "spam": {"__type__": "datetime", "isoformat": "2024-05-25T14:23:36.769090"}}]'
>>> unserialized = dtjson.loads(serialized)
>>> print(unserialized)
['foo', {'bar': ['baz', None, 1.0, 2], 'spam': datetime.datetime(2024, 5, 25, 14, 23, 36, 769090)}]
```

Timespans are also similarly support. The interface for using dtjson is nearly identical to the json module, and can be generally used as a replacement.

## Installation

**NOTE**: PyPi rejected dtjson as a package name, so this is packaged as `json-dt-serializer`.

```
pip install json-dt-serializer
```

## Usage details

Usage is nearly identical to the [json](https://docs.python.org/3/library/json.html) module, with most arguments being passed directly to it.

### dtjson.dump

```python
def dump(
    obj,
    fp,
    skipkeys=False,
    ensure_ascii=True,
    check_circular=True,
    allow_nan=True,
    cls=None,
    indent=None,
    separators=None,
    default=None,
    sort_keys=False,
    **kw
)
```

Serializes obj as a JSON formatted stream to fp (a `.write()`-supporting file-like object).

Arguments:

 - obj: The Python object to serialize.
 - fp: File-like object supporting .write() where the JSON data will be written.
 - skipkeys: If True, dict keys that are not basic types will be skipped.
 - ensure_ascii: If True, non-ASCII characters are escaped in JSON strings.
 - check_circular: If False, skips circular reference check.
 - allow_nan: If False, out of range float values will raise a ValueError.
 - cls: Custom JSONEncoder subclass.
 - indent: If non-negative integer, pretty-prints with that indent level.
 - separators: Tuple (item_separator, key_separator) to specify item and key separators.
 - default: Function that returns a serializable version of obj or raises TypeError.
 - sort_keys: If True, dictionary keys are sorted.
 - **kw: Additional keyword arguments.

### dtjson.dumps

```python
def dumps(
    obj,
    skipkeys=False,
    ensure_ascii=True,
    check_circular=True,
    allow_nan=True,
    cls=None,
    indent=None,
    separators=None,
    default=None,
    sort_keys=False,
    **kw
)
```

Serializes obj to a JSON formatted string.

Arguments:

 - obj: The Python object to serialize.
 - skipkeys: If True, dict keys that are not basic types will be skipped.
 - ensure_ascii: If True, non-ASCII characters are escaped in JSON strings.
 - check_circular: If False, skips circular reference check.
 - allow_nan: If False, out of range float values will raise a ValueError.
 - cls: Custom JSONEncoder subclass.
 - indent: If non-negative integer, pretty-prints with that indent level.
 - separators: Tuple (item_separator, key_separator) to specify item and key separators.
 - default: Function that returns a serializable version of obj or raises TypeError.
 - sort_keys: If True, dictionary keys are sorted.
 - **kw: Additional keyword arguments.

### dtjson.load

```python
def load(
    fp,
    cls=None,
    object_hook=None,
    parse_float=None,
    parse_int=None,
    parse_constant=None,
    object_pairs_hook=None,
    **kw
)
```
Deserializes fp (a `.read()`-supporting file-like object containing a JSON document) to a Python object.

Arguments:

 - fp: File-like object supporting .read() containing the JSON document.
 - cls: Custom JSONDecoder subclass.
 - object_hook: Function called with the result of any object literal decode.
 - parse_float: Function to parse JSON float values.
 - parse_int: Function to parse JSON int values.
 - parse_constant: Function called with strings like -Infinity, Infinity, NaN.
 - object_pairs_hook: Function called with an ordered list of pairs for object literal decode.
 - **kw: Additional keyword arguments.

### dtjson.loads

```python
def loads(
    s,
    cls=None,
    object_hook=None,
    parse_float=None,
    parse_int=None,
    parse_constant=None,
    object_pairs_hook=None,
    **kw
)
```

Deserializes s (a `str`, `bytes` or `bytearray` instance containing a JSON document) to a Python object.

Arguments:

 - s: A string, bytes, or bytearray instance containing the JSON document.
 - cls: Custom JSONDecoder subclass.
 - object_hook: Function called with the result of any object literal decode.
 - parse_float: Function to parse JSON float values.
 - parse_int: Function to parse JSON int values.
 - parse_constant: Function called with strings like -Infinity, Infinity, NaN.
 - object_pairs_hook: Function called with an ordered list of pairs for object literal decode.
 - **kw: Additional keyword arguments.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "json-dt-serializer",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.9",
    "maintainer_email": null,
    "keywords": null,
    "author": "Ken Kinder",
    "author_email": "ken+github@kkinder.com",
    "download_url": "https://files.pythonhosted.org/packages/ba/a5/ee544c8a7050af598eff2483df12625179ce2adf3a04a4f10102719f86f9/json_dt_serializer-1.0.1.tar.gz",
    "platform": null,
    "description": "# dtjson: json, but with datetime and timespan support\n\ndtjson builds on regular Json, but adds support for timespan and datetime objects in Python. It does this by looking for `\"__type__\": \"datetime\"` or `\"__type__\": \"timedelta\"` in the keys, with `isoformat' and `seconds` respectively.\n\nExample Usage::\n\n```python\n>>> import dtjson\n>>> import datetime\n>>> serialized = dtjson.dumps(['foo', {'bar': ('baz', None, 1.0, 2), 'spam': datetime.datetime.now()}])\n>>> print(serialized)\n'[\"foo\", {\"bar\": [\"baz\", null, 1.0, 2], \"spam\": {\"__type__\": \"datetime\", \"isoformat\": \"2024-05-25T14:23:36.769090\"}}]'\n>>> unserialized = dtjson.loads(serialized)\n>>> print(unserialized)\n['foo', {'bar': ['baz', None, 1.0, 2], 'spam': datetime.datetime(2024, 5, 25, 14, 23, 36, 769090)}]\n```\n\nTimespans are also similarly support. The interface for using dtjson is nearly identical to the json module, and can be generally used as a replacement.\n\n## Installation\n\n**NOTE**: PyPi rejected dtjson as a package name, so this is packaged as `json-dt-serializer`.\n\n```\npip install json-dt-serializer\n```\n\n## Usage details\n\nUsage is nearly identical to the [json](https://docs.python.org/3/library/json.html) module, with most arguments being passed directly to it.\n\n### dtjson.dump\n\n```python\ndef dump(\n    obj,\n    fp,\n    skipkeys=False,\n    ensure_ascii=True,\n    check_circular=True,\n    allow_nan=True,\n    cls=None,\n    indent=None,\n    separators=None,\n    default=None,\n    sort_keys=False,\n    **kw\n)\n```\n\nSerializes obj as a JSON formatted stream to fp (a `.write()`-supporting file-like object).\n\nArguments:\n\n - obj: The Python object to serialize.\n - fp: File-like object supporting .write() where the JSON data will be written.\n - skipkeys: If True, dict keys that are not basic types will be skipped.\n - ensure_ascii: If True, non-ASCII characters are escaped in JSON strings.\n - check_circular: If False, skips circular reference check.\n - allow_nan: If False, out of range float values will raise a ValueError.\n - cls: Custom JSONEncoder subclass.\n - indent: If non-negative integer, pretty-prints with that indent level.\n - separators: Tuple (item_separator, key_separator) to specify item and key separators.\n - default: Function that returns a serializable version of obj or raises TypeError.\n - sort_keys: If True, dictionary keys are sorted.\n - **kw: Additional keyword arguments.\n\n### dtjson.dumps\n\n```python\ndef dumps(\n    obj,\n    skipkeys=False,\n    ensure_ascii=True,\n    check_circular=True,\n    allow_nan=True,\n    cls=None,\n    indent=None,\n    separators=None,\n    default=None,\n    sort_keys=False,\n    **kw\n)\n```\n\nSerializes obj to a JSON formatted string.\n\nArguments:\n\n - obj: The Python object to serialize.\n - skipkeys: If True, dict keys that are not basic types will be skipped.\n - ensure_ascii: If True, non-ASCII characters are escaped in JSON strings.\n - check_circular: If False, skips circular reference check.\n - allow_nan: If False, out of range float values will raise a ValueError.\n - cls: Custom JSONEncoder subclass.\n - indent: If non-negative integer, pretty-prints with that indent level.\n - separators: Tuple (item_separator, key_separator) to specify item and key separators.\n - default: Function that returns a serializable version of obj or raises TypeError.\n - sort_keys: If True, dictionary keys are sorted.\n - **kw: Additional keyword arguments.\n\n### dtjson.load\n\n```python\ndef load(\n    fp,\n    cls=None,\n    object_hook=None,\n    parse_float=None,\n    parse_int=None,\n    parse_constant=None,\n    object_pairs_hook=None,\n    **kw\n)\n```\nDeserializes fp (a `.read()`-supporting file-like object containing a JSON document) to a Python object.\n\nArguments:\n\n - fp: File-like object supporting .read() containing the JSON document.\n - cls: Custom JSONDecoder subclass.\n - object_hook: Function called with the result of any object literal decode.\n - parse_float: Function to parse JSON float values.\n - parse_int: Function to parse JSON int values.\n - parse_constant: Function called with strings like -Infinity, Infinity, NaN.\n - object_pairs_hook: Function called with an ordered list of pairs for object literal decode.\n - **kw: Additional keyword arguments.\n\n### dtjson.loads\n\n```python\ndef loads(\n    s,\n    cls=None,\n    object_hook=None,\n    parse_float=None,\n    parse_int=None,\n    parse_constant=None,\n    object_pairs_hook=None,\n    **kw\n)\n```\n\nDeserializes s (a `str`, `bytes` or `bytearray` instance containing a JSON document) to a Python object.\n\nArguments:\n\n - s: A string, bytes, or bytearray instance containing the JSON document.\n - cls: Custom JSONDecoder subclass.\n - object_hook: Function called with the result of any object literal decode.\n - parse_float: Function to parse JSON float values.\n - parse_int: Function to parse JSON int values.\n - parse_constant: Function called with strings like -Infinity, Infinity, NaN.\n - object_pairs_hook: Function called with an ordered list of pairs for object literal decode.\n - **kw: Additional keyword arguments.\n",
    "bugtrack_url": null,
    "license": "LICENSE.txt",
    "summary": "JSON, but with datetime and timestamp support",
    "version": "1.0.1",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "53d79a3cd29b9b02aa96cf5febb722ac9ad0a5de7318a56731c48897e5c22963",
                "md5": "14a607c5c3c03ec7a9a0e18fa0ac22ba",
                "sha256": "3c3278c950845acdcc22824ea96be9c7e6129b25b8f18db83cadcca711e19b60"
            },
            "downloads": -1,
            "filename": "json_dt_serializer-1.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "14a607c5c3c03ec7a9a0e18fa0ac22ba",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.9",
            "size": 6809,
            "upload_time": "2024-05-26T16:55:03",
            "upload_time_iso_8601": "2024-05-26T16:55:03.484999Z",
            "url": "https://files.pythonhosted.org/packages/53/d7/9a3cd29b9b02aa96cf5febb722ac9ad0a5de7318a56731c48897e5c22963/json_dt_serializer-1.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "baa5ee544c8a7050af598eff2483df12625179ce2adf3a04a4f10102719f86f9",
                "md5": "25637ecadef9e57788849b263cf79270",
                "sha256": "ede04a10dc7654ac3d26a1e8d9b7f5efd36ca5197f3a9621d9f91ff18672235b"
            },
            "downloads": -1,
            "filename": "json_dt_serializer-1.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "25637ecadef9e57788849b263cf79270",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.9",
            "size": 5017,
            "upload_time": "2024-05-26T16:55:05",
            "upload_time_iso_8601": "2024-05-26T16:55:05.484207Z",
            "url": "https://files.pythonhosted.org/packages/ba/a5/ee544c8a7050af598eff2483df12625179ce2adf3a04a4f10102719f86f9/json_dt_serializer-1.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-26 16:55:05",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "json-dt-serializer"
}
        
Elapsed time: 0.27733s