- 3 minutes to read

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 example: 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 to any valid Content that return json structured data; review Formula user guide for the complete list of functions.

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

How to use

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 a garbage result). But first and foremost we have to configure the Formula plugin:

  • Select Formula as the expression type plugin.
  • Write down the expression to use in the 'Expression' text area.
  • Input proper Content as a 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 of 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 is 2.

e.g. jsonpath('Seq',body) JsonPath Simple Parameter

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 is 2.

e.g. jsonpath('Seq',context('id')) JsonPath Simple Parameter 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 Message Context 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?