asjson
json.dumps with datetime, date and bson.ObjectId support
>>> from datetime import datetime, date, timedelta, timezone >>> from decimal import Decimal >>> from bson import ObjectId >>> import asjson>>> data = { ... 'time': [ ... date(2018, 3, 6), ... datetime(2018, 3, 6, 9, 38, 0, 1), ... datetime(2018, 3, 6, 9, 38, 0, 1).replace( ... tzinfo=timezone.utc), ... ], ... 'decimal': Decimal('3.14'), ... 'objectid': ObjectId('a' * 24), ... }
We can make all the values json-appropriate without dumping the structure to string. It can be helpful in some cases, e.g. with passing it into database json field.
>>> asjson.encode(data)
{'time': ['2018-03-06',
'2018-03-06T09:38:00.000001',
'2018-03-06T09:38:00.000001+00:00'],
'decimal': '3.14',
'objectid': 'aaaaaaaaaaaaaaaaaaaaaaaa'}
For dumping to string we can use asjson.dumps which takes the same parameters as standard json.dumps does plus debug which just a shortcut for json.dumps(…, indent=4, sort_keys=True, ensure_askii=False):
>>> print(asjson.dumps(data, debug=True))
{
"decimal": "3.14",
"objectid": "aaaaaaaaaaaaaaaaaaaaaaaa",
"time": [
"2018-03-06",
"2018-03-06T09:38:00.000001",
"2018-03-06T09:38:00.000001+00:00"
]
}
Metadata
Release files for asjson 3.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| asjson-3.0.0.tar.gz | 2.2 kB | Without provenance | Details for asjson-3.0.0.tar.gz |
Release files / asjson-3.0.0.tar.gz
| Download URL | asjson-3.0.0.tar.gz |
|---|---|
| Size | 2.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
919285397066cace2a430ea83e7bd09e5d2ef2777d4ab9b8922d7c15e921f9af
|
|
BLAKE2b-256 checksum How to use checksums |
0884c3ce2005d6c0f239b511398b45a5f0620aff6b06a180a6984feac37b13d3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for asjson 3.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.