JS json-to-spec Architecture
Engine Internals

Compiler Architecture

The compilation flow from decoupled JSON inputs to valid specification JSON follows a multi-stage recursive tree traversal pipeline.

┌─────────────────────────────────────────────────────────────┐ │ 1. Normalization (compile) │ │ - Accepts inStructure & inData via in-local convention │ └──────────────────────────────┬──────────────────────────────┘ │ ▼ ┌─────────────────────────────────────────────────────────────┐ │ 2. Recursive Traversal (compileTree.js) │ │ - Array Nodes: Compile children & flatten │ │ - Object Nodes: Check operation vs standard element │ └──────────────────────────────┬──────────────────────────────┘ │ ┌──────────────────────┴──────────────────────┐ ▼ ▼ ┌──────────────────────────────┐ ┌──────────────────────────────┐ │ [operation: "iterate"] │ │ [Standard Element Node] │ │ - Resolve source collection │ │ - Clone & tag transformation │ │ - Filter isVisible: false │ │ - Interpolate textContent │ │ - Stamp template per item │ │ - Interpolate attributes │ │ - Bind $index, $number, row │ │ - Bind data values │ └──────────────┬───────────────┘ └──────────────┬───────────────┘ │ │ └───────────────────┬───────────────────┘ │ ▼ ┌─────────────────────────────────────────────────────────────┐ │ 3. Spec JSON Output (ready for json-to-dom) │ └─────────────────────────────────────────────────────────────┘

Pipeline Stages

Stage 1

Universal Tree Traversal

Traverses any arbitrary depth. Arrays are recursively mapped and automatically flattened, allowing node operations to expand dynamically into sibling nodes.

Stage 2

Operation Detection & Filter Execution

Detects operation: "iterate". Resolves collections from root data or local context, drops items marked isVisible: false, and injects $index, $number, and parent row references.

Stage 3

Token Interpolation & Control Adaptation

Interpolates ${field}, ${value}, ${title}, and deep dot-paths. Converts input elements to textarea when field metadata requires multiline input.