-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.html
53 lines (51 loc) · 1.74 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="https://cdn.jsdelivr.net/gh/rudderlabs/rudder-json-template-engine/public/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Rudder Json Template Engine</title>
</head>
<body>
<div id="app">
<h1><a href="https://transformers-workflow-engine.rudderstack.com/#/json-template">Rudder Json Template Engine</a></h1>
<div>
<h2>Template:</h2>
<textarea id="template" placeholder="Enter JSON Template" rows="10" cols="50">
.a + .b + .c</textarea
>
</div>
<div>
<h2>Data:</h2>
<textarea id="data" placeholder="Enter JSON data" rows="10" cols="50">
{"a": 1, "b": 2, "c": 3}</textarea
>
</div>
<div>
<h2>Output:</h2>
<pre id="output"></pre>
</div>
</div>
<script type="module">
import { JsonTemplateEngine } from 'https://cdn.jsdelivr.net/npm/@rudderstack/json-template-engine/build/json-template.min.js';
const template = document.getElementById('template');
const data = document.getElementById('data');
const output = document.getElementById('output');
function updateOutput() {
try {
const result = JsonTemplateEngine.evaluateAsSync(template.value, {}, JSON.parse(data.value));
output.innerText = JSON.stringify(result, null, 2);
} catch (error) {
output.innerText = error.message;
}
}
template.addEventListener('input', () => {
updateOutput()
});
data.addEventListener('input', () => {
updateOutput()
});
updateOutput();
</script>
</body>
</html>