Render Template Merge Fields With Nested Paths and Defaults
Last updated: November 29, 2026
Quick Overview
Implement a renderer for document templates containing tags like {{signer.name}} or {{company.address|Not provided}}, resolving dotted paths (including list indexes) against a nested data object, using the default when present and raising an error otherwise.
DocuSign
November 29, 20260
0
0 solved
Implement a renderer for document templates containing tags like {{signer.name}} or {{company.address|Not provided}}, resolving dotted paths (including list indexes) against a nested data object, using the default when present and raising an error otherwise.
DocuSign templates and document generation fill agreements from CRM data, so merge-field rendering is a natural screening problem. The interviewer looks for a hand-written scanner rather than a fragile regex, clear error behaviour, and an answer to escaping.
What the Interviewer Expects
- Write a single left-to-right scanner that handles tags, escapes and plain text
- Resolve dotted paths through dicts and list indexes
- Distinguish a missing value from a falsy one such as 0 or empty string
- Raise a clear error on an unclosed tag or a required field that is missing
- Keep it linear in template length
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you add formatting filters such as {{amount|currency}} without breaking defaults?
- Merge data comes from customers. What injection risks exist when the output is HTML or PDF?
- How would you validate a template against a schema before any envelope is sent?
- How would you support loops, such as one row per line item?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Tags look like {{path}} or {{path|default}}. Paths are dot separated; numeric segments index lists. Missing value with a default uses the default; without one, raise ValueError. \{{ emits a li...
High-Level Design
Scan the template with an index. At {{, find the next }}, split the inner expression on the first |, resolve the path, and append the value or the default. At the escape sequence, emit literal b...