Execution Trace & Testing Verification
Step-by-step call stack execution walkthrough, enterprise edge cases, and container testing workflows.
1. The Execution Call Stack Trace
Here is what happens inside the engine when transforming a complex enterprise payload like a Tally stock item:
1. transform(food, recipe)
→ Enters traverse({ inSource, inRecipe })
→ Type is Object: Enters traverseObject
← Returns final reshaped JSON output
→ Recipe has "transform": Enters ifTransformFound
• Matches key "STOCKITEM" → has nested "transform"
• Recurses to traverse({ inSource: STOCKITEM, inRecipe: directive })
← Constructs new root object
• Recurses to traverse({ inSource: STOCKITEM, inRecipe: directive })
→ Type is Array: Enters traverseArray
• Maps item #0 → traverse({ inSource: item[0], inRecipe })
• Applies
• Applies
• Applies
← Returns mapped & filtered array
• Applies
alterKey: "Name" → outputs clean name• Applies
valueKey: "#text" to BASEUNITS → extracts "kgs"• Applies
valueType: "array" to BATCHALLOCATIONS.LIST → returns clean array
2. Enterprise Quirks Handled by Design
- Literal Dotted Keys: Tally exports often contain literal dots in property names, such as
BATCHALLOCATIONS.LISTorLEDGERNAME.#text. BecauseifTransformFounduses direct property indexing (localTransform[key]), literal dotted keys match directly without ambiguous path splitting. - Single-Item Object / Array Inconsistency: XML parsers output an object for a single item and an array for multiple items. The
valueType: "array"directive normalizes single-item objects into arrays cleanly. - Deep Tree Cleanliness: Unwanted metadata attributes (e.g.
@_TYPE="String",@_RESERVEDNAME="") are naturally pruned because they are never listed in the recipe.
3. Development & Test Workflow
Use the containerized environment to verify tests and build the production bundle:
1. Run Real-World Enterprise Sample
# Inside container or via wslc:
wslc exec node-dev node samples/6oct/batches/index.js
# Test simple transformation:
wslc exec node-dev node samples/new/simple/index.js
2. Build Production Bundle
wslc exec node-dev npm --prefix /workspace/json-transformer run build
Builds the minified ES bundle to docs/dist/v8/min.js and copies it to docs/dist/min.js.