This iterates over the Contacts array and prints out a JSON data structure.
The CustomerName value is retrieved by navigating to the parent object using the annotation {{../CustomerName}}.
Property values are wrapped in {{#jval}} helpers. This helper will render the specified content when the value isn't null, but render the word null when it is. So if a record's FirstName value is missing or null, you would see the following output:
"FirstName": null,
Finally, the {{#continue}} helper is used to append a comma after each object in the array apart from the last.
Note that any values included in double moustaches - e.g. {{FirstName}} - will be automatically escaped. For example, double quotes will be changed to \" and any new lines will be changed to \n. If you don't want the value to be escaped, use triple moustaches: {{{FirstName}}}.
The Handlebars documentation refers to HTML escaping throughout its guidance. This is because the main way in which Handlebars is used is in generating web pages.
However, in our implementation of Handlebars, HTML escaping has been replaced with JSON escaping as described above.
Should I use JSONata or Handlebars?
There is no "right" answer for everybody. Influencing factors include your comfort with JSONata's transformation language versus Handlebars' templating language and the degree of responsibility you want to take for creating valid JSON output.
JSONata is designed for data and will guarantee that you produce valid JSON output. It will often result in shorter templates and allows you to apply filters to the JSON data itself, for example to only include contacts in a certain country in the output. It will allow you to sort, group and aggregate data.
How we write arrays of data to Parquet files
These aren't areas of functionality you can configure, though it's important you're aware how they work.
Merging arrays
Imagine we pull two records back from a NoSQL database or API sequentially. The first record is as follows:
Here's how you can accomplish this using both and :
The will give you the best guidance on how to use language and there's also a where you can test your transformations within your browser.
The will give you the best guidance on how to use language and there's also a where you can test your template within your browser.
Handlebars is designed for text templating rather than managing data. Its syntax means that the template is much more readable to the human eye. You can also make use of any of its extensive list of for manipulating numbers, strings, dates and more. Since we use Handlebars elsewhere in Datasmells - e.g. for generating queries based on previous result sets and for case templates - it also has the advantage of being familiar. However, since Handlebars allows you to create any kind of text output, the onus is on you to ensure that you create syntactically valid JSON.