Data source
While creating a document template, you can access the data model using JSONPath syntax. You can use both, the dot notation:
$.shipment.tracking_number
or the bracket notation:
$['shipment']['tracking_number']
For each document you need to select DataSource property value:
- package - prints a label for each package in the shipment;
- shipment - prints only one label for the whole shipment.
Restrictions
-
Root element starts from
$.
or.
-
Nested object path have to start from
.
If nested object starts from$.
it means reference to root element. In this case no relation will be considered. -
The leading
$.
or.
or@
is mandatory. One of these has to be used to differentiate variables from JSONPath syntax. -
Special leading char
@
can be used as reference to current object with limited usage that depends on the document type, e.g. for package document type we can use@package
as reference for each package in multi package shipment. - Keep in mind that JSONPath functions and filters (expressions) are very limited.
-
Double dots
..property
is not supported. -
Wildcard for selecting all indexed items
[*]
can be used for arrays only and it means all items in the array. -
Wildcard for selecting all properties
.*
at object is not supported, e.g.shipment.*
Syntax
Data source
Data model as the source object for JSONPath examples:
{
"shipment": {
"tracking_number": "US1234",
"packages": [{
"weight_details": {
"weight_in_grams": "12"
}
},
{
"weight_details": {
"weight_in_grams": "02"
}
}],
"metadata": {
"account.number": "1234",
"account_enabled": "true"
}
}
}
Properties
$.shipment.tracking_number
Arrays
Items can be referenced by index (starting from zero) or asterisk in the case of aggregation functions.
$.shipment.packages[0].weight_details.weight_in_grams
Sum($.shipment.packages[*].weight_details.weight_in_grams)
$['shipment']['packages'][0]['weight_details']['weight_in_grams']
Dictionaries
Generally, a dot and bracket notation can be used, but in case a dictionary key contains a dot, you have to use bracket notation - see the third example.
$.shipment.metadata.account_enabled
$.shipment.metadata['account_enabled']
$.shipment.metadata['account.number']
Current package reference
If you select package as DataSource, you can also refer to the current Package using prefix @
@package.weight_details.weight_in_grams