Name | json-dt-serializer JSON |
Version |
1.1.0
JSON |
| download |
home_page | None |
Summary | JSON, but with datetime and timestamp support |
upload_time | 2024-07-13 14:16:59 |
maintainer | None |
docs_url | None |
author | Ken Kinder |
requires_python | <4.0,>=3.9 |
license | LICENSE.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/1d/6b/057e9898a7f9bb4e610889331166b73939706d02b728b22ce026b96f18c4/json_dt_serializer-1.1.0.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.1.0",
"project_urls": null,
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "815fb454ed1009c6b79041ae8d1e005956abe3935e190c9fe6defd2513f02b40",
"md5": "dc5c933ac808f255f5b3ddbd14a9dfe1",
"sha256": "3c772f7d810d62a7a28242e22410c863e4ea6aa5a0348bd69d53ddc82cfb4ab1"
},
"downloads": -1,
"filename": "json_dt_serializer-1.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "dc5c933ac808f255f5b3ddbd14a9dfe1",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.9",
"size": 5417,
"upload_time": "2024-07-13T14:16:58",
"upload_time_iso_8601": "2024-07-13T14:16:58.271076Z",
"url": "https://files.pythonhosted.org/packages/81/5f/b454ed1009c6b79041ae8d1e005956abe3935e190c9fe6defd2513f02b40/json_dt_serializer-1.1.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "1d6b057e9898a7f9bb4e610889331166b73939706d02b728b22ce026b96f18c4",
"md5": "26280b8ff4f03456239a0236d7ff7c30",
"sha256": "46a1125981948ba08a8d63fab56ef19a77cb663f1be19bd14ee4c1979a53565f"
},
"downloads": -1,
"filename": "json_dt_serializer-1.1.0.tar.gz",
"has_sig": false,
"md5_digest": "26280b8ff4f03456239a0236d7ff7c30",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.9",
"size": 3880,
"upload_time": "2024-07-13T14:16:59",
"upload_time_iso_8601": "2024-07-13T14:16:59.582811Z",
"url": "https://files.pythonhosted.org/packages/1d/6b/057e9898a7f9bb4e610889331166b73939706d02b728b22ce026b96f18c4/json_dt_serializer-1.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-07-13 14:16:59",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "json-dt-serializer"
}