Documentation
Welcome to docs|API reference|JsonPath reference

JsonPath reference

This is the complete reference for JSONPath projection functions.

Introduction

This page contains the definition and reference for all JSONPath projection functions. To read more on how to use JSONPath projection see the section about using JSONPath projections.

Function argument defaults

To provide a simpler API that is easier to use, function arguments have default values provided for them when no value is provided in the projection definition. The default values are:

FieldSupported type(s)
eventSelector$.event
targetSelector$.projection
eventFilterNo value provided
targetFilterNo value provided
rawDataNo value provided

Basic object modification

The following sections contains functions that can be used for basic object modification.

merge

Merges event data with existing projected data.

Supported configuration

FieldSupported type(s)
eventFilterFilter expression
eventSelectorObject
targetFilterFilter expression
targetSelector
Required
Object
rawDataObject

Merge complete event data

Merges the entire event object onto the projection
{
  "eventType": "OrderStatusChangedEvent",
  "functions": [
    {
      "function": "merge"
    }
  ]
}

set

Sets/replaces the value of an existing key.

Supported configuration

FieldSupported type(s)
eventFilterFilter expression
eventSelectorAny
targetFilterFilter expression
targetSelector
Required
Any
rawDataAny

Update a single field from a field in the event

This example sets the status field to match the status field in the event.
{
  "eventType": "OrderPlaced",
  "functions": [
    {
      "function": "set",
      "eventSelector": "$.event.status",
      "targetSelector": "$.projection.status"
    }
  ]
}

unset

Removes an existing key.

Supported configuration

FieldSupported type(s)
eventFilterFilter expression
eventSelectorUnsupported
targetFilterFilter expression
targetSelector
Required
Any
rawDataUnsupported

Remove a single field from the projection

This example removed the field creditCardNumber when the CreditCardNumberCleared is processed.
{
  "eventType": "CreditCardNumberCleared",
  "functions": [
    {
      "function": "unset",
      "targetSelector": "$.projection.customer.creditCardNumber"
    }
  ]
}

clear

Clear the entire projection or a specific field, i.e reset it to a default value.

Supported configuration

FieldSupported type(s)
eventFilterFilter expression
eventSelectorUnsupported
targetFilterFilter expression
targetSelector
Required
Any
rawDataUnsupported

Default data types

When the field is cleared, the data in the projection will be reset to a default value. Depending on what data type the object in the projection has, the default value will be different. The following table shows the default values for different data types:

Data typeSupported type(s)
String""
Booleanfalse
Number0
Array[]
Object{}

Clear all items in a list

This example clears the items from the projection and resets it to an empty list.
{
  "eventType": "ShoppingBagCleared",
  "functions": [
    {
      "function": "clear",
      "targetSelector": "$.projection.items"
    }
  ]
}

delete

Delete a projection. Future requests will result in a 404 Not Found.

Supported configuration

FieldSupported type(s)
eventFilterFilter expression
eventSelectorUnsupported
targetFilterUnsupported
targetSelectorUnsupported
rawDataUnsupported

Delete a projection

This example deletes an order projection when an OrderDeleted event is processed.
{
  "eventType": "OrderDeleted",
  "functions": [
    {
      "function": "delete"
    }
  ]
}

Collection functions

The following functions can be used to work with collections such as Arrays/Lists and Sets.

append

Adds anything to the end of an array/list.

Supported configuration

FieldSupported type(s)
eventFilterFilter expression
eventSelectorAny
targetFilterFilter expression
targetSelectorCollection
rawDataAny

Append an item to a list

This example takes all data from the event as an object and adds it to the end of the placedOrders list in the projection.
{
  "eventType": "OrderPlaced",
  "functions": [
    {
      "function": "append",
      "targetSelector": "$.projection.placedOrders"
    }
  ]
}

prepend

Adds anything to the beginning of an array/list.

Supported configuration

FieldSupported type(s)
eventFilterFilter expression
eventSelectorAny
targetFilterFilter expression
targetSelectorCollection
rawDataAny

Prepend an item to a list

This example takes all data from the event as an object and adds it to the beginning of the placedOrders list in the projection.
{
  "eventType": "OrderPlaced",
  "functions": [
    {
      "function": "prepend",
      "targetSelector": "$.projection.placedOrders"
    }
  ]
}

addtoset

Adds anything to a Set. The insertion order will be maintained within the Set.

Supported configuration

FieldSupported type(s)
eventFilterFilter expression
eventSelectorAny
targetFilterFilter expression
targetSelectorCollection
rawDataAny

Adds an element to a set

This example adds the userId from the event UserLoggedIn to the set activeUser. If the same user logs in again, the set will not be modified.
{
  "eventType": "UserLoggedIn",
  "functions": [
    {
      "function": "addtoset",
      "eventSelector": "$.event['userId']",
      "targetSelector": "$.projection.activeUsers"
    }
  ]
}

Arithmetic functions

The following functions can be used to perform simple arithmetic operations on numbers.

add

Performs addition on two numbers.

Supported configuration

FieldSupported type(s)
eventFilterFilter expression
eventSelectorNumber
targetFilterFilter expression
targetSelectorNumber
rawDataNumber

Add to a field

This example adds the total amount from the OrderPlaced event to a totalAmount field in the projection.
{
  "eventType": "OrderPlaced",
  "functions": [
    {
      "function": "add",
      "eventSelector": "$.event['orderAmount']",
      "targetSelector": "$.projection.totalAmount"
    }
  ]
}

inc

Increases a number by one

Supported configuration

FieldSupported type(s)
eventFilterFilter expression
eventSelectorUnsupported
targetFilterFilter expression
targetSelectorNumber
rawDataUnsupported

Increase a number by one

This example increased the field placedOrders by one when an OrderPlaced event is processed.
{
  "eventType": "OrderPlaced",
  "functions": [
    {
      "function": "inc",
      "targetSelector": "$.projection.placedOrders"
    }
  ]
}

subtract

Subtracts two numbers.

Supported configuration

FieldSupported type(s)
eventFilterFilter expression
eventSelectorNumber
targetFilterFilter expression
targetSelectorNumber
rawDataNumber

Subtract from a field

This example removed the amount in the field orderAmount in the OrderRefunded event from the totalAmount field in the projection.
{
  "eventType": "OrderRefunded",
  "functions": [
    {
      "function": "subtract",
      "eventSelector": "$.event['orderAmount']",
      "targetSelector": "$.projection.totalAmount"
    }
  ]
}

dec

Decreases a number by one

Supported configuration

FieldSupported type(s)
eventFilterFilter expression
eventSelectorUnsupported
targetFilterFilter expression
targetSelectorNumber
rawDataUnsupported

Decrease a number by one

This example decreases the field pendingOrders by one when an OrderCanceled event is processed.
{
  "eventType": "OrderCanceled",
  "functions": [
    {
      "function": "dec",
      "targetSelector": "$.projection.pendingOrders"
    }
  ]
}

References

The following functions can be used to work with projection references.

setref

Adds a reference to the field, making it filterable using reference queries.

Supported configuration

FieldSupported type(s)
eventFilterFilter expression
eventSelectorUnsupported
targetFilterUnsupported
targetSelectorString/Number/Date
rawDataString/Number/Date

Set a reference to a date field

This example sets the date from the orderDate field in the OrderPlaced event to the orderDate field in the projection, then adding a reference to the field in the projection
{
  "eventType": "OrderPlaced",
  "functions": [
    {
      "function": "set",
      "eventSelector": "$.event.orderDate"
      "targetSelector": "$.projection.orderDate"
    },
    {
      "function": "setref",
      "targetSelector": "$.projection.orderDate"
    }
  ]
}

clearref

Removes the reference from the projection.

Supported configuration

FieldSupported type(s)
eventFilterFilter expression
eventSelectorUnsupported
targetFilterUnsupported
targetSelectorUnsupported
rawDataUnsupported

Clear a reference

This example clears the reference from the projection when OrderCanceled event is processed. After the OrderCanceled is processed, the projection will still be retrievable by id but not filterable via reference.
{
  "eventType": "OrderCanceled",
  "functions": [
    {
      "function": "clearref"
    }
  ]
}