json field setter

JSON Field Setter

Version: 17.07

Supported Since: 17.07

What is a JSON Field Setter?

A JSON Field Setter is a processing element which sets a given value to a field, specified by the key at a given JSON path, of a message payload.

In order to use this processing element, you must first select the JSON Operations dependency from the processors list when you are creating an empty Ultra project. If you have already created a project, you can add this dependency via Component Registry. From Tools menu, select Ultra Studio → Component Registry and from the Processors list, select the JSON Operations dependency.

json field setter outports

Out Ports

Next

The resulting message context will be sent to this outport after setting the specified key-value pair at the provided JSON path according to the given configurations, if the process is completed successfully.

On Exception

The message context will be sent to this outport if any exception occurred while setting the field at the provided JSON path

Parameters

JSON Path

JSON path of the field specified by the key which is to be added or modified

For additional information please refer to the JSON Path section of JSON Feature documentation

Key Name

Name of the key which is to be set at the specified JSON path of the message payload. Key can be a plain text or any combination of placeholder expressions such as @{message.headers.<name>}, @{message.properties.<name>}, @{mc.properties.<name>}, @{variable.<name>}

Type of Value

Type of the value to be assigned to the specified key at the provided JSON path

[Type of Value] Value to Assign

Value of the selected type to be assigned to the specified key at the provided JSON path. Value can be a plain text or any combination of placeholder expressions such as @{message.headers.<name>}, @{message.properties.<name>}, @{mc.properties.<name>}, @{variable.<name>}

Add Key if Absent

Whether to add the given key-value pair at the specified JSON path if the key does not exist

Sample Use Case

In the following use case, the requirement is to receive a message with a JSON payload from an HTTP NIO Ingress Connector, set a the value to a specified key at a given JSON path of the received message payload and deliver the message to a backend service via an HTTP NIO Egress Connector.

The challenge is to set the specified key-value pair at the given JSON path.

json field setter flow
json field setter config

In this flow a JSON Field Setter processing element is configured to set the sample key postalCode at the JSON path: $.address of the input JSON payload with the value: 81000.

For the following sample input JSON payload a new key-value pair will be added into the address.

 {
    "first-name": "John",
    "last-name" : "Doe",
    "age"      : 24,
    "address"  : {
      "streetAddress": "1st Cross Street",
      "city"         : "Colombo"
    },
    "telephone-numbers": [
      {
        "type"  : "mobile",
        "number": "074-234-567-890"
      },
      {
        "type"  : "land line",
        "number": "011-234-567-890"
      }
    ]
 }

Final result will be as follows,

 {
    "first-name": "John",
    "last-name" : "Doe",
    "age"      : 24,
    "address"  : {
      "streetAddress": "1st Cross Street",
      "city"         : "Colombo",
      "postalCode"   : "81000"
    },
    "telephone-numbers": [
      {
        "type"  : "mobile",
        "number": "074-234-567-890"
      },
      {
        "type"  : "land line",
        "number": "011-234-567-890"
      }
    ]
 }
In this topic
In this topic
Contact Us