Registry / serialization / standardjson

standardjson

JSON →
library0.3.1pypiunverified

StandardJSON is a Python library that provides a JSON encoder aiming for full compliance with the ECMA-262 (JavaScript) and ECMA-404 (JSON Data Interchange) specifications. It extends Python's built-in `json.JSONEncoder` to natively serialize additional Python types such as `datetime.datetime`, `datetime.date`, `datetime.time`, and `decimal.Decimal` objects. The latest version is 0.3.1, released in May 2014, and the project appears to be unmaintained.

pip install standardjson
INSTALL
IMPORT
SIG · STANDARDJSON
S
standardjson
serializationenv0.3.1
Install
1.5s avg
Import
11ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.3.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.012s · 17.8MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 1.5s · import 0.010s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

StandardJSONEncoder
from standardjson import StandardJSONEncoder
StandardJSONEncoder (pre-0.3.0)
from standardjson.encoders import StandardJSONEncoder
from standardjson import StandardJSONEncoder
In versions 0.3.0 and later, StandardJSONEncoder was moved to the 'encoders' module, though the top-level import might be re-exposed via __init__.py in 0.3.1. For strictness, or if the top-level import fails, use the explicit path.

Use `StandardJSONEncoder` as you would use `json.JSONEncoder` from the Python standard library, passing it to the `cls` argument of `json.dumps()` or `json.dump()`.

import datetime import json from standardjson import StandardJSONEncoder # Example with datetime.date data = {'event_date': datetime.date(2023, 1, 15)} json_output = json.dumps(data, cls=StandardJSONEncoder, indent=2) print(f"Serialized date: {json_output}") # Expected output: {"event_date": "2023-01-15"} import decimal # Example with decimal.Decimal data_decimal = {'price': decimal.Decimal('19.99')} json_output_decimal = json.dumps(data_decimal, cls=StandardJSONEncoder, indent=2) print(f"Serialized decimal: {json_output_decimal}") # Expected output: {"price": "19.99"}
Debug
Known issues
deprecatedThe `standardjson` library appears unmaintained, with its last release (0.3.1) in May 2014. It has not received updates for Python 3.6+ compatibility or recent JSON specification changes.
fix
Consider using more actively maintained alternatives like `orjson`, `jsons`, or handling custom types with the `default` parameter of the standard `json` library for modern Python applications.
affects: <=0.3.1
breakingVersion 0.3.0 introduced breaking changes, including renaming the package to `standardjson` and moving `StandardJSONEncoder` into the `encoders` submodule.
fix
If upgrading from pre-0.3.0, update imports from `from standardjson import StandardJSONEncoder` to `from standardjson.encoders import StandardJSONEncoder` if the top-level import is not resolved.
affects: 0.3.0, 0.3.1
gotchaThe library was primarily tested for Python 2.6, 2.7, and 3.3. While it might run on newer Python versions (3.4, 3.5), it is not officially supported or tested beyond these versions, which may lead to unexpected behavior or incompatibilities on Python 3.6+.
fix
Thoroughly test on your target Python version or use a more modern JSON serialization library that explicitly supports your Python runtime.
affects: All versions on Python >3.5
gotchaDespite its name, Python's built-in `json` module is not strictly compliant with the JSON specification (ECMA-404 / RFC 8259) by default, particularly regarding `NaN`, `Infinity`, and `-Infinity` floating-point values which it encodes as their JavaScript equivalents rather than raising an error. `standardjson` aims for stricter compliance.
fix
Be aware of these differences, especially when interacting with systems expecting strict JSON compliance. `standardjson` itself aims to adhere to the spec, but ensure the final output is validated against your receiving system's expectations if using other tools in the pipeline.
affects: All versions
Errors
Common errors & fixes
TypeError: Object of type datetime.date is not JSON serializable
Attempting to serialize `datetime.date` (or `datetime.datetime`, `datetime.time`, `decimal.Decimal`) objects using the standard `json.dumps` function without specifying `StandardJSONEncoder`.
fix
Pass `cls=StandardJSONEncoder` to `json.dumps()` or `json.dump()`. Example: `json.dumps(data, cls=StandardJSONEncoder)`.
AttributeError: module 'standardjson' has no attribute 'StandardJSONEncoder'
This error occurs if `StandardJSONEncoder` is not exposed directly in the `standardjson` top-level package or if an older version (pre-0.3.0) is in use with an incorrect import path, or if `__init__.py` does not re-export it.
fix
Try importing explicitly from the `encoders` submodule: `from standardjson.encoders import StandardJSONEncoder`. Ensure you are on version 0.3.0 or later for this path.
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Attempting to decode a string that is not valid JSON, such as one with single quotes instead of double quotes for keys/strings, unquoted keys, or trailing commas.
fix
Ensure the JSON string strictly adheres to the JSON specification (e.g., all keys and string values must be double-quoted, no trailing commas, no comments). Use a JSON validator to identify syntax errors.
Upgrade
Version history
0.3.1latest on PyPI · released May 21, 2014
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources

No resource links recorded.