{"id":18582097,"url":"https://github.com/lorefnon/hbs-jsonpath-helper","last_synced_at":"2026-04-30T02:37:40.977Z","repository":{"id":35044646,"uuid":"200154147","full_name":"lorefnon/hbs-jsonpath-helper","owner":"lorefnon","description":"A simple handlebars helper that enables you to use jsonpath (to access and traverse nested data) within your templates","archived":false,"fork":false,"pushed_at":"2023-10-18T04:10:09.000Z","size":452,"stargazers_count":1,"open_issues_count":4,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-10T16:11:55.633Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lorefnon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-08-02T02:55:48.000Z","updated_at":"2024-07-01T22:38:59.000Z","dependencies_parsed_at":"2022-08-25T06:11:01.360Z","dependency_job_id":null,"html_url":"https://github.com/lorefnon/hbs-jsonpath-helper","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lorefnon%2Fhbs-jsonpath-helper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lorefnon%2Fhbs-jsonpath-helper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lorefnon%2Fhbs-jsonpath-helper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lorefnon%2Fhbs-jsonpath-helper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lorefnon","download_url":"https://codeload.github.com/lorefnon/hbs-jsonpath-helper/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253823419,"owners_count":21969846,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T00:09:14.052Z","updated_at":"2026-04-30T02:37:35.943Z","avatar_url":"https://github.com/lorefnon.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# hbs-jsonpath-helper\n\nA simple handlebars helper that enables you to use jsonpath (to access and traverse nested data) within your templates\n\n## Resources:\n\n- Baeldung's [Introduction to jsonpath](https://www.baeldung.com/guide-to-jayway-jsonpath)\n- Online [jsonpath evaluator](https://jsonpath.com/)\n- [jsonpath-plus](https://www.npmjs.com/package/jsonpath-plus) npm package (which the helpers defined here delegate to)\n\n\n## Installation \u0026 Usage\n\n```\nnpm install --save handlebars hbs-jsonpath-helper\n```\n\n```js\nconst Handlebars = require('handlebars');\nconst jsonPathHelper = require('hbs-jsonpath-helper');\n\njsonPathHelper.register();\n// Or, you can explicitly pass a Handlebars instance\njsonPathHelper.register(Handlebars);\n\n// Compile template\nconst template = Handlebars.compile(`\n{{jp-get \"$.store.book[0].title\"}}\n`);\n\n// Data passed to the template\nconst data = { /* ... */ }\n\n// Use compiled template:\nconst str = template(data); // \"Nigel Rees\"\n```\n\n## API \u0026 Examples\n\nFor the following data source\n\n```\nconst data = {\n  store: {\n    book: [\n      {\n        category: 'reference',\n        author: 'Nigel Rees',\n        title: 'Sayings of the Century',\n        price: 8.95,\n      },\n      {\n        category: 'fiction',\n        author: 'Evelyn Waugh',\n        title: 'Sword of Honour',\n        price: 12.99,\n      },\n      {\n        category: 'fiction',\n        author: 'Herman Melville',\n        title: 'Moby Dick',\n        isbn: '0-553-21311-3',\n        price: 8.99,\n      },\n      {\n        category: 'fiction',\n        author: 'J. R. R. Tolkien',\n        title: 'The Lord of the Rings',\n        isbn: '0-395-19395-8',\n        price: 22.99,\n      },\n    ],\n    bicycle: {\n      color: 'red',\n      price: 19.95,\n    },\n  },\n};\n\n```\n\n\n### jp-get\n\nRetrieve a value from current context using jsonpath\n\n*Template:*\n\n```\n\u003ch1\u003eBooks\u003c/h1\u003e\n\u003cul\u003e\n  {{#each (jp-get \"$.store.book[*]\")}}\n      \u003cli\u003e\n        \u003cdiv class=\"title\"\u003e{{title}}\u003c/div\u003e\n        \u003cdiv class=\"author\"\u003e{{author}}\u003c/div\u003e\n      \u003c/li\u003e\n  {{/each}}\n\u003c/ul\u003e\n```\n\n*Result:*\n\n```\n\u003ch1\u003eBooks\u003c/h1\u003e\n\u003cul\u003e\n      \u003cli\u003e\n        \u003cdiv class=\"title\"\u003eSayings of the Century\u003c/div\u003e\n        \u003cdiv class=\"author\"\u003eNigel Rees\u003c/div\u003e\n      \u003c/li\u003e\n      \u003cli\u003e\n        \u003cdiv class=\"title\"\u003eSword of Honour\u003c/div\u003e\n        \u003cdiv class=\"author\"\u003eEvelyn Waugh\u003c/div\u003e\n      \u003c/li\u003e\n      \u003cli\u003e\n        \u003cdiv class=\"title\"\u003eMoby Dick\u003c/div\u003e\n        \u003cdiv class=\"author\"\u003eHerman Melville\u003c/div\u003e\n      \u003c/li\u003e\n      \u003cli\u003e\n        \u003cdiv class=\"title\"\u003eThe Lord of the Rings\u003c/div\u003e\n        \u003cdiv class=\"author\"\u003eJ. R. R. Tolkien\u003c/div\u003e\n      \u003c/li\u003e\n\u003c/ul\u003e\n```\n\n\n### jp-get-in\n\nRetrieve a value from specified target using jsonpath\n\n*Template:*\n\n```\n\u003ch1\u003eBooks\u003c/h1\u003e\n\u003cul\u003e\n  {{#each (jp-get-in \"book[*]\" store)}}\n      \u003cli\u003e\n        \u003cdiv class=\"title\"\u003e{{title}}\u003c/div\u003e\n        \u003cdiv class=\"author\"\u003e{{author}}\u003c/div\u003e\n      \u003c/li\u003e\n  {{/each}}\n\u003c/ul\u003e\n```\n\n*Result:*\n\n```\n\u003ch1\u003eBooks\u003c/h1\u003e\n\u003cul\u003e\n      \u003cli\u003e\n        \u003cdiv class=\"title\"\u003eSayings of the Century\u003c/div\u003e\n        \u003cdiv class=\"author\"\u003eNigel Rees\u003c/div\u003e\n      \u003c/li\u003e\n      \u003cli\u003e\n        \u003cdiv class=\"title\"\u003eSword of Honour\u003c/div\u003e\n        \u003cdiv class=\"author\"\u003eEvelyn Waugh\u003c/div\u003e\n      \u003c/li\u003e\n      \u003cli\u003e\n        \u003cdiv class=\"title\"\u003eMoby Dick\u003c/div\u003e\n        \u003cdiv class=\"author\"\u003eHerman Melville\u003c/div\u003e\n      \u003c/li\u003e\n      \u003cli\u003e\n        \u003cdiv class=\"title\"\u003eThe Lord of the Rings\u003c/div\u003e\n        \u003cdiv class=\"author\"\u003eJ. R. R. Tolkien\u003c/div\u003e\n      \u003c/li\u003e\n\u003c/ul\u003e\n```\n\n\n### jp-descend\n\nUse the value derived from current context using jsonpath as the context\nfor embedded block\n\n*Template:*\n\n```\n\u003ch1\u003eAuthors\u003c/h1\u003e\n\u003cul\u003e\n  {{#jp-descend \"$.store.book[*].author\"}}\n      {{#each .}}\n          \u003cli\u003e{{.}}\u003c/li\u003e\n      {{/each}}\n  {{/jp-descend}}\n\u003c/ul\u003e\n```\n\n*Result:*\n\n```\n\u003ch1\u003eAuthors\u003c/h1\u003e\n\u003cul\u003e\n          \u003cli\u003eNigel Rees\u003c/li\u003e\n          \u003cli\u003eEvelyn Waugh\u003c/li\u003e\n          \u003cli\u003eHerman Melville\u003c/li\u003e\n          \u003cli\u003eJ. R. R. Tolkien\u003c/li\u003e\n\u003c/ul\u003e\n```\n\n\n### jp-descend-in\n\nUse the value derived from specified target using jsonpath as the context\nfor embedded block\n\n*Template:*\n\n```\n\u003ch1\u003eAuthors\u003c/h1\u003e\n\u003cul\u003e\n  {{#jp-descend-in \"book[*].author\" store}}\n      {{#each .}}\n          \u003cli\u003e{{.}}\u003c/li\u003e\n      {{/each}}\n  {{/jp-descend-in}}\n\u003c/ul\u003e\n```\n\n*Result:*\n\n```\n\u003ch1\u003eAuthors\u003c/h1\u003e\n\u003cul\u003e\n          \u003cli\u003eNigel Rees\u003c/li\u003e\n          \u003cli\u003eEvelyn Waugh\u003c/li\u003e\n          \u003cli\u003eHerman Melville\u003c/li\u003e\n          \u003cli\u003eJ. R. R. Tolkien\u003c/li\u003e\n\u003c/ul\u003e\n```\n\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Florefnon%2Fhbs-jsonpath-helper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Florefnon%2Fhbs-jsonpath-helper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Florefnon%2Fhbs-jsonpath-helper/lists"}