feat: Add parseJson Handlebars Helper to Support Processing Nested JSON Data (#31998)

Co-authored-by: AdrianKoszalka <adrian.koszalka@techminers.com>
This commit is contained in:
Adrian Koszałka
2025-02-06 21:48:28 +01:00
committed by GitHub
parent 649a0dec6c
commit 205cff3a94
3 changed files with 74 additions and 2 deletions

View File

@@ -99,5 +99,18 @@ Handlebars.registerHelper(
},
);
// usage: {{parseJson jsonString}}
Handlebars.registerHelper('parseJson', (jsonString: string) => {
try {
return JSON.parse(jsonString);
} catch (error) {
if (error instanceof Error) {
error.message = `Invalid JSON string: ${error.message}`;
throw error;
}
throw new Error(`Invalid JSON string: ${String(error)}`);
}
});
Helpers.registerHelpers(Handlebars);
HandlebarsGroupBy.register(Handlebars);