{"id":1553,"library":"microsoft-kiota-serialization-json","title":"Microsoft Kiota JSON Serialization","description":"microsoft-kiota-serialization-json provides JSON serialization and deserialization capabilities for Kiota-generated Python SDKs. It includes factories for creating JSON serialization writers and parse nodes, enabling the conversion of `Parsable` objects to and from JSON format. The library is part of the larger Microsoft Kiota ecosystem and is currently at version 1.10.1, with frequent synchronized releases across its components.","status":"active","version":"1.10.1","language":"en","source_language":"en","source_url":"https://github.com/microsoft/kiota-python","tags":["microsoft","kiota","serialization","json","openapi","sdk","codegen"],"install":[{"cmd":"pip install microsoft-kiota-serialization-json","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Provides core interfaces like Parsable, ParseNode, and SerializationWriter which are fundamental to the serialization process.","package":"microsoft-kiota-abstractions","optional":false}],"imports":[{"symbol":"JsonSerializationWriterFactory","correct":"from microsoft_kiota_serialization_json import JsonSerializationWriterFactory"},{"symbol":"JsonParseNodeFactory","correct":"from microsoft_kiota_serialization_json import JsonParseNodeFactory"},{"note":"Required for defining models that can be serialized/deserialized by Kiota.","symbol":"Parsable","correct":"from microsoft_kiota_abstractions.serialization import Parsable"}],"quickstart":{"code":"import io\nfrom typing import Callable, Dict, Optional\nfrom uuid import UUID\n\nfrom microsoft_kiota_abstractions.serialization import Parsable, ParseNode, SerializationWriter\nfrom microsoft_kiota_serialization_json import JsonParseNodeFactory, JsonSerializationWriterFactory\n\nclass MyModel(Parsable):\n    \"\"\"A simple model for demonstration.\"\"\"\n    def __init__(self) -> None:\n        self._id: Optional[UUID] = None\n        self._name: Optional[str] = None\n        self.additional_data: Dict[str, object] = {}\n\n    @property\n    def id(self) -> Optional[UUID]:\n        return self._id\n\n    @id.setter\n    def id(self, value: Optional[UUID]) -> None:\n        self._id = value\n\n    @property\n    def name(self) -> Optional[str]:\n        return self._name\n\n    @name.setter\n    def name(self, value: Optional[str]) -> None:\n        self._name = value\n\n    def get_field_deserializers(self) -> Dict[str, Callable[[ParseNode], None]]:\n        \"\"\"Gets the deserialization information for the current model.\"\"\"\n        return {\n            \"id\": lambda n: setattr(self, 'id', n.get_uuid_value()),\n            \"name\": lambda n: setattr(self, 'name', n.get_str_value()),\n        }\n\n    def serialize(self, writer: SerializationWriter) -> None:\n        \"\"\"Serializes properties of the current model into a writer.\"\"\"\n        writer.write_uuid_value(\"id\", self.id)\n        writer.write_str_value(\"name\", self.name)\n        writer.write_additional_data_value(self.additional_data)\n\n# --- Usage Example ---\n\n# 1. Create a model instance\nmy_object = MyModel()\nmy_object.id = UUID(\"12345678-1234-5678-1234-567812345678\")\nmy_object.name = \"Test Item\"\nmy_object.additional_data[\"status\"] = \"active\"\n\n# 2. Serialize the model to JSON\nwriter_factory = JsonSerializationWriterFactory()\n# Use 'application/json' for JSON content type\nwith writer_factory.get_serialization_writer(\"application/json\") as writer:\n    # Pass None as the key for the root object\n    writer.write_object_value(None, my_object)\n    serialized_content_bytes = writer.get_serialized_content()\n\nprint(\"Serialized JSON:\")\nprint(serialized_content_bytes.decode('utf-8'))\n\n# 3. Deserialize the JSON back into a model instance\nparse_node_factory = JsonParseNodeFactory()\nwith parse_node_factory.get_parse_node(\"application/json\", serialized_content_bytes) as parse_node:\n    deserialized_object = parse_node.get_object_value(MyModel)\n\nprint(\"\\nDeserialized object:\")\nprint(f\"ID: {deserialized_object.id}\")\nprint(f\"Name: {deserialized_object.name}\")\nprint(f\"Additional data: {deserialized_object.additional_data}\")\n\n# Verify deserialization\nassert deserialized_object.id == my_object.id\nassert deserialized_object.name == my_object.name\nassert deserialized_object.additional_data[\"status\"] == my_object.additional_data[\"status\"]\nprint(\"\\nSerialization and deserialization successful!\")","lang":"python","description":"This example demonstrates how to serialize a `Parsable` object to JSON and then deserialize it back using `JsonSerializationWriterFactory` and `JsonParseNodeFactory`. It defines a simple `MyModel` class implementing the `Parsable` interface from `microsoft-kiota-abstractions`."},"warnings":[{"fix":"Upgrade your Python environment to version 3.10, 3.11, 3.12, or 3.13.","message":"Starting with version 1.10.0, support for Python 3.9 has been dropped. Ensure your environment uses Python 3.10 or newer.","severity":"breaking","affected_versions":">=1.10.0"},{"fix":"Ensure that your data models implement the `Parsable` interface correctly. For general JSON handling, consider `json` or `pydantic`.","message":"This library is designed specifically for serializing and deserializing models that implement the `microsoft_kiota_abstractions.serialization.Parsable` interface, typically generated by the Kiota OpenAPI SDK generator. It is not intended as a general-purpose JSON serialization library for arbitrary Python objects.","severity":"gotcha","affected_versions":"All"},{"fix":"For a direct object JSON output, pass `None` or an empty string as the key to `write_object_value` when serializing the top-level object. E.g., `writer.write_object_value(None, my_model)`.","message":"When serializing a root object using `writer.write_object_value()`, the key parameter should typically be `None` or an empty string, especially if the resulting JSON should be a single object. Providing a non-None, non-empty key will wrap the object under that key.","severity":"gotcha","affected_versions":"All"},{"fix":"Verify that `microsoft-kiota-abstractions` is present in your environment (`pip show microsoft-kiota-abstractions`). If not, explicitly install it (`pip install microsoft-kiota-abstractions`).","message":"This library relies heavily on `microsoft-kiota-abstractions`. If you install `microsoft-kiota-serialization-json` directly, ensure `microsoft-kiota-abstractions` is also installed (it's a dependency, but manual inspection might be needed if dependency resolution issues arise).","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}