Skip to main content

JSON with datetime support

Project description

Sick of rewriting the same JSON datetime handling code for each project? jsondate is a drop-in replacement for Python’s standard json library that adds sensible handling of datetime and date objects.

jsondate uses ISO8601 for encoding datetime objects and the date-specific part of ISO6801 for encoding date objects.

Example:

import datetime
import jsondate as json

>>> data = json.dumps(dict(created_at=datetime.datetime(2012, 10, 31)))
'{"created_at": "2012-10-31T00:00:00Z"}'

>>> json.loads(data)
{u'created_at': datetime.datetime(2012, 10, 31, 0, 0)}

>>> date = json.dumps(dict(date=datetime.date(2012, 10, 31)))
'{"date": "2012-10-31"}'

>>> json.loads(data)
{u'created_at': datetime.date(2012, 10, 31)}

Unicode Empty Strings

The json standard library module will return unicode objects for all strings except empty strings, which are returned as str objects.

This inconsistency can be annoying when using libraries that expect all input to be unicode.

jsondate fixes this by returning empty-strings as unicode objects as well.

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

jsondate-0.1.2.tar.gz (3.5 kB view details)

Uploaded Source

File details

Details for the file jsondate-0.1.2.tar.gz.

File metadata

  • Download URL: jsondate-0.1.2.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for jsondate-0.1.2.tar.gz
Algorithm Hash digest
SHA256 7ecc7144ae207c72fcf73b1563e1762e38404ea9f069ec7f50f0f5dc59f23f7e
MD5 74ea0b9da2a9a900bc35001dd40e4581
BLAKE2b-256 31683289811a68f56478ffd1cf790f875e01c00c1abd941d5c9459d5cd7beaf1

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