Skip to main content

JSON Extra | JSON that gives you extra datetime, uuid and bytes data types

Project description

jsonextra

Build Status Codecov PyPI Version License

same as json library, but with extra support for bytes, uuid and datetime data classes

Installation

$ pip install jsonextra

Usage

Use just like json as normal once imported, but with addition of extra data classes.

import uuid, datetime  # for creation of `my_data` object
import jsonextra

my_data = {'id': uuid.uuid4(), 'created': datetime.date.today()}
# my_data --> {'id': uuid.UUID('5f7660c5-88ea-46b6-93e2-860d5b7a0271'), 'created': datetime.date(2019, 6, 16)}

# Serializes the key values to stringified versions
my_json = jsonextra.dumps(my_data)
# my_json --> '{"id": "5f7660c5-88ea-46b6-93e2-860d5b7a0271", "created": "2019-06-16"}'

# Deserializes the object and confirms the output matches `my_data`
assert jsonextra.loads(my_json) == my_data  # True
.dump(obj, fp, **kwargs) & .dumps(obj, **kwargs)

Will serialize extra data classes into their string representations (__str__). Note: for datetime objects, the __str__ is dumped to an ISO8601-like format: yyyy-mm-dd HH:MM:SS, and it is the same format that will be expected by .loads method.

.load(fp, **kwargs) & .loads(s, **kwargs)

Will deserialize any stings, which match patterns of extra supported data classes. For example, if something looks like a uuid - it will be converted to uuid.UUID. If this behaviour is undesired, please use the built-in json.loads method instead of jsonextra.loads.

Supported extra data classes

  • datetime.date
  • datetime.datetime
  • uuid.UUID
  • bytes

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

jsonextra-0.3.0-py2.py3-none-any.whl (4.3 kB view hashes)

Uploaded Python 2 Python 3

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