When you integrate with third-party tools, you might want to fetch data from these tools to further define and configure nuanced workflows. With JSON parser node, parse information from all tools you integrate with and use them to better define your workflows in Freshservice.


What are JSON Parser nodes?


The JSON Parser node enables you to parse any JSON payload within the workflow context and use the outputs with the following conditions and actions. 


With JSON Parser nodes you can capture responses from Orchestration apps and Web Request nodes to use them within the workflow conditions and actions. 



JSONPath


A JSONPath is a query language for JSON. Outputs can be generated automatically or configured manually using JSON path expressions. 


A JSONPath expression specifies a path to an element (or a set of elements) in a JSON structure. Paths can use the dot notation. The leading $ represents the root object.


Eg:  $.Address.city.name refers to Bengaluru from the above payload.


Other JSON elements are described below with a sample ticket payload.


{

  "ticket": {

    "priority": 3,

    "requester_id": 1000000678,

    "source": 2,

    "status": 2,

    "subject": "Ticket Title",

    "id": 266,

    "type": "Incident"

      "assets": [

      {

        "name": "Logitech Mouse",

        "ci_type_id": 27000336397,

        "impact": 2

      },

      {

        "name": "Dell Monitor",

        "ci_type_id": 27000336384,

        "impact": 1

      },

     ]

    }

   }


Expression

Description

Example 

Output

$

The root object or array.


$.ticket refers to the 

Object “ticket” from the root path.

All direct properties of the ticket.

 {

"priority": 3,

"requester_id": 1000000678,

"source": 2,

"status": 2,

"subject": "Ticket Title",

"id": 266,

"type": "Incident"

"assets": [

 {

 "name": "Logitech Mouse",

 "ci_type_id": 27000336397,

 "impact": 2

  },

  {

  "name": "Dell Monitor",

  "ci_type_id": 27000336384,

  "impact": 1

      },

     ]

    }

   


.property

Selects the specified property in a parent object.

$.ticket.priority refers to the priority of the ticket. 

The Priority of the ticket


Result: 1

[n]

Selects the n-th element from an array. Indexes are 0-based.

$.ticket.assets[0] refers to the
first asset associated with the ticket. 

The properties of the first asset associated with the ticket.

{

 "name": "Logitech Mouse",

 "ci_type_id": 27000336397,

 "impact": 2

  }

..property

Recursive descent: Searches for the specified property name recursively and returns an array of all values with this property name. Always returns a list, even if just one property is found.

$.ticket.assets[*]

$..assets[*] Both expressions give the list of all the assets associated with the ticket.


All the assets associated with the ticket.


[

{

"name": "Logitech Mouse",

"ci_type_id": 27000336397,

"impact": 2

 },

 {

 "name": "Dell Monitor",

 "ci_type_id": 27000336384,

 "impact": 1

  },

  ]


*

A wildcard expression is an expression of either * or [*]. Wildcard operator returns all objects or elements regardless of their names.

$.ticket.assets[*] refers to all the assets associated with the ticket.

All the assets associated with the ticket.


[

{

"name": "Logitech Mouse",

"ci_type_id": 27000336397,

"impact": 2

 },

 {

 "name": "Dell Monitor",

 "ci_type_id": 27000336384,

 "impact": 1

  },

  ]


[start:end]

[start:]

Selects array elements from the start index and up to, but not including, end index. If the end is omitted, selects all elements from start until the end of the array. 

$..assets[0,1].name

$..assets[:2].name Both

Expressions refer to the name of the first two assets.

Name of the first two assets associated with the ticket.


[

  "Logitech Mouse",

  "Dell Monitor"

]

[?(expression)]

? ( ) to query all items that meet certain criteria.

$.ticket.assets[?(@.impact<2)].name refers to the asset name in the ticket that has an impact of less than 2

An asset that has an impact of less than 2(low).


Result: Dell Monitor

Refers to the current object or element in filter expressions.

$..assets[?(@.impact=2)] refers to all the assets that has medium impact.

An asset that has an impact 2 (medium).

Result: Logitech Mouse

[(expression)]

Script expressions can be used instead of explicit property names or indexes. An example is [(@.length-1)] which selects the last item in an array. Here, length refers to the length of the current array rather than a JSON field named length.

$..assets[-1:].name

$..assets[(@.length-1)].name


Both expressions refer to the name of the last asset associated with the ticket. 


Name of the last asset associated with the ticket.



[

  "Dell Monitor"

]



To explore more use cases, do refer to the articles here.


-> Sample Usecase - Invoking a Web Request and parsing its response using the JSON Parser node.

-> Sample Usecase - Getting Custom Attributes For Active Directory User and parsing the attributes using the JSON Parser node

->Sample Usecase- Invoke WebRequest node to fetch ticket details and perform actions based on it.