Skip to main content

Extended JSON(ESON)

JSON is great for sharing data in a human readable format but sometimes it lacks in object types support. ESON does not re-invent the wheel, it just provides a base for you to implement extended JSON objects allowing you to share data between services, apps and languages as objects.

ESON comes with built in extensions for date and datetime. You can write your own extensions to manage custom data.

This is the python version of ESON. See other languages here

Getting Started

Install

Run pip install eson

Usage

Below is a summary of various operations using eson. Click here to open a live test environment.

Encoding:

from datetime import datetime, date
import eson

user = {
    "name": "Jane Doe",
    "date_of_birth": date.today(),
    "registered": datetime.now()
}

# Encoding the data
eson_data = eson.encode(user, pretty=True)

# Sample output
"""
{
    "name": "Jane Doe",
    "EsonDate~date_of_birth": {"year": 2020, "month": 04, "day": 10},
    "EsonDatetime~registered": {...}
}
"""

Decoding

import eson

# A timezone aware date object
eson_data = '{"EsonDatetime~eatime": {"timestamp": 1588822240000400, "timezone": {"offset": 10800, "name": "EAT"}}}'
data = eson.decode(eson_data)

print(data.get("eatime"))
# Expected output '2020-05-07 06:30:40.000400+03:00'

Extending ESON

You can extend ESON to achieve various purposes, e.g loading a database entity when you recieve it's ID

Below is the sample code used to extend Date objects in ESON

from datetime import date
from eson import EsonExtension

class EsonDate(EsonExtension):
    # Extend this method, use it to check whether you should encode this value
    def should_encode(self, value) -> bool:
        return type(value) == date

    def encode(self, value):
        # Encode your value to valid JSON object
        return dict(year=value.year, month=value.month, day=value.day)

    def decode(self, encoded_value):
        # Decode your object to an object relevant to your application
        return date(**encoded_value)

Once an extension is created, at the entry of your application add the extension to ESON

import eson

eson.add_extension(EsonDate)

That's it, your extension is ready to encode objects.

Metadata

Release files for eson 0.0.3

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

Source distribution (sdist)

Source distribution for eson 0.0.3
File Size Uploaded Provenance Actions
eson-0.0.3.tar.gz 4.2 kB Without provenance Details for eson-0.0.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for eson 0.0.3
File Interpreter ABI Platform Actions
eson-0.0.3-py3-none-any.whl Python 3 none any Details for eson-0.0.3-py3-none-any.whl

Total release size: 9.6 kB

Release files / eson-0.0.3.tar.gz

Download URL eson-0.0.3.tar.gz
Size 4.2 kB
Tags Source
SHA-256 checksum
How to use checksums
c911fb50c50a0083f374c82d16c71a56950ac155c2abdae9edeb2606ef348fc8
BLAKE2b-256 checksum
How to use checksums
68035edf0d5f15362c0d1aa372d3f0d04492b347d898c3d0c065a82a20279990
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2

Release files / eson-0.0.3-py3-none-any.whl

Download URL eson-0.0.3-py3-none-any.whl
Size 5.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dc40dae574efd61d993fb4080e55aeb47a83591a143c71f6aed48071b1781e5a
BLAKE2b-256 checksum
How to use checksums
9be1cf0fae1f17376962363119057a44d6f35ea20a0e85e7729d066e082d5a2e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2

Security for eson 0.0.3

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