Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
hbs-jsonpath-helper
Advanced tools
A simple handlebars helper that enables you to use jsonpath (to access and traverse nested data) within your templates
A simple handlebars helper that enables you to use jsonpath (to access and traverse nested data) within your templates
npm install --save handlebars hbs-jsonpath-helper
const Handlebars = require('handlebars');
const jsonPathHelper = require('hbs-jsonpath-helper');
jsonPathHelper.register();
// Or, you can explicitly pass a Handlebars instance
jsonPathHelper.register(Handlebars);
// Compile template
const template = Handlebars.compile(`
{{jp-get "$.store.book[0].title"}}
`);
// Data passed to the template
const data = { /* ... */ }
// Use compiled template:
const str = template(data); // "Nigel Rees"
For the following data source
const data = {
store: {
book: [
{
category: 'reference',
author: 'Nigel Rees',
title: 'Sayings of the Century',
price: 8.95,
},
{
category: 'fiction',
author: 'Evelyn Waugh',
title: 'Sword of Honour',
price: 12.99,
},
{
category: 'fiction',
author: 'Herman Melville',
title: 'Moby Dick',
isbn: '0-553-21311-3',
price: 8.99,
},
{
category: 'fiction',
author: 'J. R. R. Tolkien',
title: 'The Lord of the Rings',
isbn: '0-395-19395-8',
price: 22.99,
},
],
bicycle: {
color: 'red',
price: 19.95,
},
},
};
Retrieve a value from current context using jsonpath
Template:
<h1>Books</h1>
<ul>
{{#each (jp-get "$.store.book[*]")}}
<li>
<div class="title">{{title}}</div>
<div class="author">{{author}}</div>
</li>
{{/each}}
</ul>
Result:
<h1>Books</h1>
<ul>
<li>
<div class="title">Sayings of the Century</div>
<div class="author">Nigel Rees</div>
</li>
<li>
<div class="title">Sword of Honour</div>
<div class="author">Evelyn Waugh</div>
</li>
<li>
<div class="title">Moby Dick</div>
<div class="author">Herman Melville</div>
</li>
<li>
<div class="title">The Lord of the Rings</div>
<div class="author">J. R. R. Tolkien</div>
</li>
</ul>
Retrieve a value from specified target using jsonpath
Template:
<h1>Books</h1>
<ul>
{{#each (jp-get-in "book[*]" store)}}
<li>
<div class="title">{{title}}</div>
<div class="author">{{author}}</div>
</li>
{{/each}}
</ul>
Result:
<h1>Books</h1>
<ul>
<li>
<div class="title">Sayings of the Century</div>
<div class="author">Nigel Rees</div>
</li>
<li>
<div class="title">Sword of Honour</div>
<div class="author">Evelyn Waugh</div>
</li>
<li>
<div class="title">Moby Dick</div>
<div class="author">Herman Melville</div>
</li>
<li>
<div class="title">The Lord of the Rings</div>
<div class="author">J. R. R. Tolkien</div>
</li>
</ul>
Use the value derived from current context using jsonpath as the context for embedded block
Template:
<h1>Authors</h1>
<ul>
{{#jp-descend "$.store.book[*].author"}}
{{#each .}}
<li>{{.}}</li>
{{/each}}
{{/jp-descend}}
</ul>
Result:
<h1>Authors</h1>
<ul>
<li>Nigel Rees</li>
<li>Evelyn Waugh</li>
<li>Herman Melville</li>
<li>J. R. R. Tolkien</li>
</ul>
Use the value derived from specified target using jsonpath as the context for embedded block
Template:
<h1>Authors</h1>
<ul>
{{#jp-descend-in "book[*].author" store}}
{{#each .}}
<li>{{.}}</li>
{{/each}}
{{/jp-descend-in}}
</ul>
Result:
<h1>Authors</h1>
<ul>
<li>Nigel Rees</li>
<li>Evelyn Waugh</li>
<li>Herman Melville</li>
<li>J. R. R. Tolkien</li>
</ul>
MIT
FAQs
A simple handlebars helper that enables you to use jsonpath (to access and traverse nested data) within your templates
The npm package hbs-jsonpath-helper receives a total of 5 weekly downloads. As such, hbs-jsonpath-helper popularity was classified as not popular.
We found that hbs-jsonpath-helper demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.