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 standardjsonVerified import paths — ran on the pinned version, not inferred.
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()`.
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.
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.
Thoroughly test on your target Python version or use a more modern JSON serialization library that explicitly supports your Python runtime.
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.
Pass `cls=StandardJSONEncoder` to `json.dumps()` or `json.dump()`. Example: `json.dumps(data, cls=StandardJSONEncoder)`.
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.
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.
No dependency data recorded yet.
No resource links recorded.