Formula - jsonpath

jsonpath('Expression',body) Formula function implemented JSONPath functionality, it extracts data from json body structure by navigating into a specific element and retrieve one or more unique values .

Quick example

Let's get you started with the following simple demonstration example valid for this Formula plugin. For other and more advanced examples please scroll down on this page to the Examples section.

Input Expression Result

  {"seq":2}


jsonpath('seq',body)

2
Text Data jsonpath expression Unique values

Features

  • Extracts data from json structure.
  • Uses ordinary JSON Path expression.
  • Extract all the unique values from Content.
  • Can be applied on any valid Content that return json structured data; review Formula user guide for complete list of functions.

This plugin loads the entire message into RAM, so make sure to apply this function on smaller messages only

How to use

In order to use the jsonpath function the Content parameter should contain a json structure data string (otherwise it will fail and you will end up with garbage result). But first and foremost we have to configure the Formula plugin:

  • Select Formula as expression type plugin.
  • Write down the expression to use in the 'Expression' text area.
  • Input a proper Content as parameter to the function.

Syntax

Use the jsonpath function with any of the following parameters:

  • From Message Body: jsonpath('Expression ',body)

  • From Message Context: jsonpath('Expression',context('MessageContextKey'))

  • Result from previous Formula operation jsonpath('Expression',SomeOtherNestedFormulaFunction(Content))

Examples

Below you will find different common examples for how to use the jsonpath function.

Body as Content

The body content is JSON structure with one element called "Seq" that is equal, by using the provided expression the result will be 2.

e.g. jsonpath('Seq',body) JsonPath_simpleParameter

Message Body


  {"Seq":2}

Expression


jsonpath('Seq',body)


Context as Content

The Message context value is JSON structure with one element called "Seq", by using the provided expression the result will be 2.

e.g. jsonpath('Seq',context('id')) JsonPath_simpleParameter_MessageContext

Message Context Value


  {"Seq":2}

Expression


jsonpath('Seq',context('id'))


Formula Function as Content

The Message Context value is JSON array contains multiple Id's each one of these values corresponding a certain Message Context key , here we are applying regex function on key field and return a unique list of JSON elements values by using valid JSONPath syntax expression.

e.g. jsonpath('$..Id',context(regex('id.*'))) JsonPath_messageContext_multiples

Message Context Value


[{ "Id": 0 },{ "Id": 1 },{ "Id": 1 },{ "Id": 2 }] 


[{ "Id": 3 },{ "Id": 4 },{ "Id": 5 },{ "Id": 6 }]

Expression


jsonpath('$..Id',context(regex('id.*')))


Next Step

How to Add or manage Search Fields
How to Add or manage Log Views

Expression Type Plugins are used in Search Fields
What are Search Fields?
What are Search Field Expressions?
What are Message Types?
What are Log Views?