Skip to main content
Altcraft Docs LogoAltcraft Docs Logo
User guideDeveloper guideAdmin guide
Company siteHelp center
English
  • Русский
  • English
v74
  • v74
  • v73
  • v72
Login
  • User documentation
  • FAQ
  • Altcraft glossary
  • Profiles and databases
  • Communication channels
  • Segmentation
  • Message templates
    • Working with message templates
    • Visual editor for email-template
    • Template fragments
    • Image gallery
    • Content personalization
    • Creating tables based on array elements
    • Block editor for email template
    • Altcraft Variables and Functions
      • Logical expressions in messages
      • Loops in messages
      • Market variables in templates
      • Using the JSONPath functionality
    • Dynamic content in messages
    • Importing and exporting a message template
    • Importing a template from a third-party service
    • Exporting a template from Pixcraft
  • Mailings
  • Campaigns
  • Automation scenarios
  • Market
  • Loyalty programs
  • Reports and analytics
  • Integrations
  • Weblayers
  • Settings
  • API requests: where to start
  • Changelog
  • library
  • Message templates
  • Altcraft Variables and Functions
  • Using the JSONPath functionality
Documentation for version v74

Using the JSONPath functionality

The Altcraft platform supports the functionality of the JSONPath query language when working with JSON content. JSONPath syntax allows you to quickly and easily select objects within code and use them message templates. It can be used when working with API content and with external JSON content.

API content allows you to change the content of the trigger message each time it is sent. The required variable can be specified in the trigger API request. You can learn more about how to run triggered mailings and how to work with API content in messages here.

To use external JSON content, go to the Options section when creating or editing a template and provide a link to the dynamic JSON content source. The platform will automatically determine the fields of the external JSON file. More information about using JSON when working with message templates can be found here.

The JSONPath variable on the Altcraft platform is specified as follows:

{jsonpath(json.<root_object> "<path_to_object>" "<output_format>")}

Function arguments​

ArgumentDescription
Root objectAccessing a JSON object that contains the desired parameter or object
Path to objectThe path to the desired object can consist of segments separated by dots, logical operators, filters or functions
Output formatThe final variable can be represented in two versions: item or array. Item will display the first result found for the request, and if there is no result, it will return an empty string. Array returns an array of all results found. This mode always outputs the result as an array, even if there is only one or no result.

Usage examples​

Let's look at examples of using JSONPath. Suppose we have a JSON file with the following content:


{
"store": {
"book": [
{
"category": "reference",
"author": "Nigel Rees",
"title": "Sayings of the Century",
"price": 8.95,
"images": ["AbeLincoln.png","Churchill.jpg","Thatcher.png"]
},
{
"category": "fiction",
"author": "Evelyn Waugh",
"title": "Sword of Honour",
"price": 12.99,
"images": ["MenAtArms.png","Gentlemen.jpg","Officers.png"]
},
{
"category": "fiction",
"author": "Herman Melville",
"title": "Moby Dick",
"isbn": "0-553-21311-3",
"price": 8.99,
"images": ["Ahab.png","Ishmael.jpg","whale.png"]

},
{
"category": "fiction",
"author": "J. R. R. Tolkien",
"title": "The Lord of the Rings",
"isbn": "0-395-19395-8",
"price": 22.99
}
]
}
}

With JSONPath functionality, a small expression can return an array containing all the authors of the books:

{jsonpath(json.store "$.book[*].author" "array")}

Another expression will return one object, the author of the first book:

{jsonpath(json.store "$.book[*].author" "item")}

You can build a more complex function, for example, in order to find out the name of a book whose price is higher than 10, we will compose the following code:

{jsonpath(json.store "$.book[?(@.price > 10)].title" "item")}

To find out the arithmetic average of the price of all books, we can use this function:

{jsonpath(json.store "$.book[*].price.avg()" "item")}

JSONPath variables can also be run in loops:


{for $index $imgs = jsonpath(json.store "$.book[*].images" "array")}
<li>{$imgs}</li>
{else}
<p>Empty array!</p>
{end}

The full functionality of JSONPath on the Altcraft Marketing platform is listed in the table below:

ArgumentDescriptionUse exampleResult
$Root element{jsonpath(json.store "$.book[0].title" "item")}Sayings of the Century
@Current element{jsonpath(json.store "$.book[?(@.price > 10)].title" "item")}Sword of Honour
..Recursive descent{jsonpath(json.store "$..title" "array")}[Sayings of the Century Sword of Honour Moby Dick The Lord of the Rings]
*Match all objects{jsonPath(json.store "$.book[*].price" "array")}[8.95 12.99 8.99 22.99]
?()Filter{jsonpath(json.store "$.book[?(@.category == 'reference')].title" "item")}Sayings of the Century
Boolean operator for filteringDescriptionUse exampleResult
==Equal to{jsonpath(json.store "$.book[?(@.category == 'reference')].title" "item")}Sayings of the Century
!=Not equal to{jsonpath(json.store "$.book[?(@.category != 'reference')].title" "array")}[Sword of Honour Moby Dick The Lord of the Rings]
<Less than{jsonpath(json.store "$.book[?(@.price < 10)].title" "array")}[Sayings of the Century Moby Dick]
>Greater than{jsonpath(json.store "$.book[?(@.price > 10)].title" "array")}[Sword of Honour The Lord of the Rings]
<=Less than or equal to{jsonpath(json.store "$.book[?(@.price >= 12.99)].title" "array")}[Sword of Honour The Lord of the Rings]
>=Greater than or equal to{jsonpath(json.store "$.book[?(@.price <= 12.99)].title" "array")}[Sayings of the Century Sword of Honour Moby Dick]
FunctionDescriptionUse exampleResult
maxMaximum value in array{jsonPath(json.store "$.book[*].price.max()" "item")}22.99
minMinimum value in array{jsonPath(json.store "$.book[*].price.min()" "item")}8.95
firstFirst array element{jsonPath(json.store "$.book[*].title.first()" "item")}Sayings of the Century
lastLast array element{jsonPath(json.store "$.book[*].title.last()" "item")}The Lord of the Rings
sumSum of numbers in the array{jsonPath(json.store "$.book[*].price.sum()" "item")}53.92
avgAverage of the numbers in the array{jsonPath(json.store "$.book[*].price.avg()" "item")}13.48
lengthNumber of elements in the array{jsonPath(json.store "$.book.length()" "item")}4
Last updated on May 13, 2024
Previous
Market variables in templates
Next
Dynamic content in messages
  • Function arguments
  • Usage examples
© 2015 - 2025 Altcraft, LLC. All rights reserved.