Skip to main content

Parsing

parse​

This helper converts a STRING into a structured object at runtime.

It supports:

Input starts withParsed as
<XML
{JSON object
[JSON array

JSON example​

{{#with (parse '{"name":"Laptop","price":1000}')}}
Name:
{{name}}
Price:
{{price}}
{{/with}}

Result:

Name: Laptop
Price: 1000

JSON array example​

{{#each (parse "[1,2,3]")}}
<div>{{this}}</div>
{{/each}}

Result:

<div>1</div>
<div>2</div>
<div>3</div>

XML example​

{{#with
(parse
"
<product>
<name>Laptop</name>
<price>1000</price>
</product>
"
)
}}

{{name}}
{{price}}

{{/with}}

Result:

Laptop
1000

Parse + Each example​

{{#each
(parse
'
[
{"name":"Laptop"},
{"name":"Mouse"},
{"name":"Keyboard"}
]
'
)
}}

<li>{{name}}</li>

{{/each}}

Result:

<li>Laptop</li>
<li>Mouse</li>
<li>Keyboard</li>

Dynamic Parse from Variable​

We have this data:

{
"#text": "{\"name\":\"Laptop\",\"price\":1000}"
}

We can use:

{{#with (parse jsonText)}}
{{name}}
-
{{price}}
{{/with}}

Result:

Laptop - 1000