pipr.tools
Pipes
Clean Email Strip formatting from pasted email for clean plain text Clean AI Output Clean plain text from ChatGPT or AI output Decode & Format JWT Decode a JWT and pretty-print header and payload Word Frequency Count word frequency in text

mustache-render Render Mustache template with JSON data

</> Web
Input0 chars
Output0 chars

Examples

Render a Mustache template with JSON data

Usage
"Hello, {{name}}! You have {{count}} messages.
---
{"name":"A..." | mustache-render

Preview a personalized order confirmation email

Usage
"Hi {{first_name}},

Your order #{{order_id}} has shipped!

T..." | mustache-render

Generate a blog post header from template + metadata

Usage
"# {{title}}

By {{author}} | {{date}}

{{summary}}
---
{"tit..." | mustache-render
View source
async (input)=>{
                const sep = input.indexOf("\n---\n");
                if (sep === -1) return "Error: separate template and JSON data with a line containing only ---";
                const template = input.slice(0, sep);
                const dataStr = input.slice(sep + 5);
                try {
                    const { default: Mustache } = await import('mustache').then(async (m)=>{
                        await m.__tla;
                        return m;
                    });
                    const data = JSON.parse(dataStr);
                    return Mustache.render(template, data);
                } catch (e) {
                    return `Error: ${e.message}`;
                }
            }