Skip to content

Serializer

The serializer converts evaluated resources into deployment-ready output. Each lexicon provides its own serializer implementation.

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.

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 an AttrRef into a Declarable with kind: "output". The serializer emits it into the template’s Outputs section.
  • ChildProjectInstance — a Declarable representing 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.

Each lexicon serializer defines how evaluator values map to the target format:

Evaluator ValueTypical Output
StringJSON string
NumberJSON number
BooleanJSON boolean
NullOmitted (in objects) or null (in arrays)
ArrayJSON array
ObjectJSON object (null properties omitted)
ResourceRefProvider-specific reference intrinsic

See your lexicon’s serialization documentation for the concrete mapping.