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 sts-json-datetime 0.0.10

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

Source distribution (sdist)

Source distribution for sts-json-datetime 0.0.10
File Size Uploaded
sts-json-datetime-0.0.10.tar.gz 4.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for sts-json-datetime 0.0.10
File Interpreter ABI Platform
sts_json_datetime-0.0.10-py3-none-any.whl Python 3 none any Details

Total release size: 8.7 kB

Release files / sts-json-datetime-0.0.10.tar.gz

Download URL sts-json-datetime-0.0.10.tar.gz
Size 4.0 kB
Tags Source
SHA-256 checksum
How to use checksums
7bdcaa3cfd42bafea316b497fa864fd51bedb4a1f2a0873d817659c282bf7698
BLAKE2b-256 checksum
How to use checksums
2cf399fd8fbb714578dc48cbd19450e250cf9542ca3b46d4866178e4d40ed815
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.0.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.2

Release files / sts_json_datetime-0.0.10-py3-none-any.whl

Download URL sts_json_datetime-0.0.10-py3-none-any.whl
Size 4.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e9e4d50b72f4fcac9834ce33f167b932902aa29d8597d621f31c30087dd911c9
BLAKE2b-256 checksum
How to use checksums
030f0a508be277f6ebc9c973bab94d26a0ae34ac909950034c3aab3963a86dae
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.0.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.2

Release history Release notifications | RSS feed

This release

0.0.10 This release

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

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