Skip to main content

Allows for proper decoding of datetime values contained in JSON streams

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sts-json-datetime-0.0.8.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

sts_json_datetime-0.0.8-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file sts-json-datetime-0.0.8.tar.gz.

File metadata

  • Download URL: sts-json-datetime-0.0.8.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for sts-json-datetime-0.0.8.tar.gz
Algorithm Hash digest
SHA256 f55796976914e0b6f57c09196d1c10810df8bbc848128bf49291554e94b48c32
MD5 e1a5002ecb8a7045c0885745aa86c00d
BLAKE2b-256 d4a19945150dc5821e7b00bca086ab8316b0e8cfa01758320801da50f4e71002

See more details on using hashes here.

File details

Details for the file sts_json_datetime-0.0.8-py3-none-any.whl.

File metadata

  • Download URL: sts_json_datetime-0.0.8-py3-none-any.whl
  • Upload date:
  • Size: 4.4 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for sts_json_datetime-0.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 f7d547b8d9993d69e309df964cbd94d71e2b1b01621c2cdbaf34b1fd0acd7d4a
MD5 df33fa4e76e997f69da46ed290bf6786
BLAKE2b-256 980db9c6d7c79c977ae1b3928bf95536ca99b4e024cc864b14660ce73c454ba2

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page