JSON Writer¶
The JSON writer serializes headerkit IR into JSON, useful for inspection, debugging, inter-process communication, or as input to custom code generators.
Writer Class¶
JsonWriter
¶
Bases: BaseWriter
Writer that serializes headerkit IR to JSON.
Options¶
indent : int | None JSON indentation level. Defaults to 2. None for compact output.
Example¶
::
from headerkit.writers import get_writer
writer = get_writer("json", indent=4)
json_string = writer.write(header)
Convenience Functions¶
header_to_json
¶
Convert a Header IR to a JSON string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
header
|
Header
|
Parsed header IR. |
required |
indent
|
int | None
|
JSON indentation level. None for compact output. |
2
|
Returns:
| Type | Description |
|---|---|
str
|
JSON string representing the header and all declarations. |