Serializer
The serializer converts evaluated resources into deployment-ready output. Each lexicon provides its own serializer implementation.
Interface
Section titled “Interface”The serializer receives the full list of evaluated resources from a project and produces the final output.
interface Serializer { name: string; rulePrefix: string; serialize(entities: Map<string, Declarable>, outputs?: LexiconOutput[]): string | SerializerResult;}
interface SerializerResult { /** Primary template content */ primary: string; /** Additional files keyed by filename */ files?: Record<string, string>;}When serialize() returns a SerializerResult instead of a plain string, the build pipeline writes additional files alongside the primary output. This is used by lexicons that support multi-file output such as nested stacks.
Child Projects
Section titled “Child Projects”Lexicons that split resources into separate deployment units (nested stacks, modules, linked templates) use chant’s child project pattern. A child project is a subdirectory that builds independently to a valid template.
The core provides two primitives:
stackOutput(ref)— wraps anAttrRefinto aDeclarablewithkind: "output". The serializer emits it into the template’sOutputssection.ChildProjectInstance— aDeclarablerepresenting a reference to a child project directory. The build pipeline detects these and recursively builds the child before serialization.
During build, findInfraFiles() stops recursing when it encounters a child project subdirectory — that directory is a separate project scope. The parent’s ChildProjectInstance entity triggers the child’s build, and the serializer uses the child’s BuildResult to produce the additional output files.
Cross-stack references are explicit: the child declares stackOutput() exports, and the parent reads them via a Proxy on the ChildProjectInstance.outputs property. The Proxy creates lexicon-specific intrinsic objects (e.g. NestedStackOutputRef for AWS) that serialize to the appropriate reference syntax.
The AWS lexicon’s nestedStack() is the reference implementation.
Value Mapping
Section titled “Value Mapping”Each lexicon serializer defines how evaluator values map to the target format:
| Evaluator Value | Typical Output |
|---|---|
| String | JSON string |
| Number | JSON number |
| Boolean | JSON boolean |
| Null | Omitted (in objects) or null (in arrays) |
| Array | JSON array |
| Object | JSON object (null properties omitted) |
| ResourceRef | Provider-specific reference intrinsic |
See your lexicon’s serialization documentation for the concrete mapping.