{"library":"smithy-json","title":"Smithy JSON","type":"library","description":"smithy-json provides robust JSON serialization and deserialization capabilities specifically for Smithy tooling within the Python ecosystem. It allows conversion between Smithy's abstract syntax tree (AST) representation (Nodes) and JSON strings. As part of the broader `smithy-python` project, it currently stands at version 0.2.2 and undergoes active development with frequent releases aligning with the main project.","language":"python","status":"active","last_verified":"Fri Apr 17","install":{"commands":["pip install smithy-json"],"cli":null},"imports":["from smithy_json.emitters import JsonEmitter","from smithy_json.parser import JsonParser","from smithy_python_types.main import Node"],"auth":{"required":false,"env_vars":[]},"links":{"homepage":"https://smithy.io","github":"https://github.com/smithy-lang/smithy-python","docs":null,"changelog":"https://github.com/smithy-lang/smithy-python/blob/develop/packages/smithy-json/CHANGELOG.md","pypi":"https://pypi.org/project/smithy-json/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null},"quickstart":{"code":"import io\nfrom smithy_python_types.main import Node\nfrom smithy_json.emitters import JsonEmitter\n\n# Create a Smithy Node representing a complex JSON object\nnode = Node.object({\n    \"greeting\": Node.string(\"Hello, Smithy!\"),\n    \"count\": Node.number(123),\n    \"enabled\": Node.boolean(True),\n    \"items\": Node.array([\n        Node.string(\"item1\"),\n        Node.object({\"id\": Node.number(1)}),\n        Node.null()\n    ])\n})\n\n# Instantiate the JSON Emitter\nemitter = JsonEmitter()\n\n# Create a buffer to write the JSON output to\noutput_buffer = io.BytesIO()\n\n# Emit the Node as JSON into the buffer\nemitter.emit(node, output_buffer)\n\n# Get the bytes from the buffer and decode to a string\njson_output = output_buffer.getvalue().decode('utf-8')\n\nprint(\"Generated JSON:\")\nprint(json_output)\n\n# Example of parsing (optional)\n# from smithy_json.parser import JsonParser\n# parser = JsonParser()\n# input_json = b'{\"parsed_key\": \"parsed_value\"}'\n# parsed_node = parser.parse(io.BytesIO(input_json))\n# print(\"\\nParsed Node:\", parsed_node)\n","lang":"python","description":"This quickstart demonstrates how to create a Smithy `Node` object (representing a JSON structure) and then use `smithy_json.emitters.JsonEmitter` to serialize it into a JSON string. This process is central to generating JSON based on Smithy models.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}