{"id":28428,"library":"typing-json","title":"typing-json","description":"Type-aware Python JSON serialization and validation. Provides decorators and functions to encode/decode Python objects with type hints, with support for Union, Optional, and nested dataclasses. Current version 0.1.3, released 2023; low release cadence.","status":"active","version":"0.1.3","language":"python","source_language":"en","source_url":"https://github.com/sg495/typing-json","tags":["json","serialization","type-hints","dataclasses","validation"],"install":[{"cmd":"pip install typing-json","lang":"bash","label":"Install from PyPI"}],"dependencies":[{"reason":"Required for compatibility with Python <3.10 (e.g., Literal, get_type_hints)","package":"typing_extensions","optional":false}],"imports":[{"note":"The public API is exposed at the top-level package.","wrong":"from typing_json.serializer import to_json","symbol":"to_json","correct":"from typing_json import to_json"},{"note":"","wrong":"","symbol":"from_json","correct":"from typing_json import from_json"}],"quickstart":{"code":"from dataclasses import dataclass\nfrom typing import Optional\nfrom typing_json import to_json, from_json\n\n@dataclass\nclass Person:\n    name: str\n    age: int\n    email: Optional[str] = None\n\n# Serialize\nperson = Person('Alice', 30)\njson_str = to_json(person)\nprint(json_str)  # '{\"name\": \"Alice\", \"age\": 30, \"email\": null}'\n\n# Deserialize\nperson2 = from_json(json_str, Person)\nprint(person2)  # Person(name='Alice', age=30, email=None)","lang":"python","description":"Defines a dataclass with optional field, serializes to JSON, then deserializes back."},"warnings":[{"fix":"Use explicit discriminators or avoid ambiguous Union types. For numbers, prefer the broader type (e.g., float).","message":"Union types are only supported if the alternatives are distinct types (e.g., int vs str). If multiple types share the same base or are ambiguous (e.g., Union[int, float]), deserialization may fail or produce wrong type.","severity":"gotcha","affected_versions":"*"},{"fix":"Always pass `ensure_ascii=True` if you need ASCII-only JSON, or rely on current default but be aware it might change.","message":"The function `to_json` defaults to `ensure_ascii=False`, which may produce non-ASCII characters. Future versions may change this.","severity":"deprecated","affected_versions":"<0.2.0"},{"fix":"Ensure all nested objects are dataclasses or have registered serializers. Use `@json` decorator from `typing_json` library (experimental) for plain classes.","message":"Nested dataclasses are supported, but only if all fields are serializable. If a field is a custom class without type hints, serialization fails silently or raises TypeError.","severity":"gotcha","affected_versions":"*"}],"env_vars":null,"last_verified":"2026-05-09T00:00:00.000Z","next_check":"2026-08-07T00:00:00.000Z","problems":[{"fix":"Convert the object to a dataclass or use `to_json` on a supported type. If it's a custom class, consider using the `@json` decorator (see docs).","cause":"The type is not a dataclass, a primitive, or registered. The library cannot serialize it.","error":"TypeError: Object of type <class '...'> is not JSON serializable"},{"fix":"Check the input JSON and ensure it conforms to the expected types. For optional fields, ensure `null` is allowed.","cause":"The JSON value for a field does not match the declared type hint (e.g., string in an int field).","error":"typing_json.errors.ValidationError: Expected type <class 'int'>, got <class 'str'>"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}