Skip to main content

JSON-datetime

https://secure.travis-ci.org/nicolaiarocci/json-datetime.png?branch=master

JSON-datetime allows for proper decoding of datetime values contained in JSON streams.

The problem

The JSON standard RFC 4627 does not support datetime types. These are usually represented as strings and Python decoders end up decoding them as such. Consider the following example:

import simplejson as json

>>> test = '{"name": "John Doe", "born": "Thu, 1 Mar 2012 10:00:49 UTC"}'
>>> json.loads(test)
{'born': u'Thu, 1 Mar 2012 10:00:49 UTC', 'name': u'John Doe'}

As you can see, in the resulting dictionary born is still a string.

The solution

JSON-datetime is a very simple wrapper around Python simplejson loads method. It decodes datetime values contained in JSON strings:

import jsondatetime as json

>>> test = '{"name": "John Doe", "born": "Thu, 1 Mar 2012 10:00:49 UTC"}'
>>> json.loads(test)
{'name': 'John Doe', 'born': datetime.datetime(2012, 3, 1, 10, 0 ,49)}

Strings are parsed using dateutil.parser.parse which is fairly flexible for common datetime formats

Custom parsing

Being just a wrapper around the loads method, you can still use all the standard loads arguments, object_hook included. This means that you can still perform custom parsing of your inbound JSON stream.

Installation

pip install json-datetime

Metadata

Release files for JSON-Datetime 0.0.6

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

Source distribution (sdist)

Source distribution for JSON-Datetime 0.0.6
File Size Uploaded Provenance Actions
JSON-Datetime-0.0.6.tar.gz 3.9 kB Without provenance Details for JSON-Datetime-0.0.6.tar.gz

Release files / JSON-Datetime-0.0.6.tar.gz

Download URL JSON-Datetime-0.0.6.tar.gz
Size 3.9 kB
Tags Source
SHA-256 checksum
How to use checksums
975dde1877fe70a6d191794e8c82cebe386804e2067d9c35b3fdda3b4da72fe3
BLAKE2b-256 checksum
How to use checksums
876a1d957962a483cf51455180e7a6e6972386f67f891ae5032f8b6c63b0af0a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.12.1 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/2.7.17

Security for JSON-Datetime 0.0.6

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.

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