json feature

JSON Feature

Version: 17.07

Supported Since: 17.07

JSON Feature

JSON Feature provides a collection of API methods that can be used to process JSON related payloads.

APIs Java Docs

convertToSOAP11

Parameters
XMessage message

Current message with JSON message payload.

This API will convert the provided JSON message payload into a SOAP11 message payload.

convertToSOAP11

Parameters
XMessage message

Current message with JSON message payload.

String rootElementName

Name of the XML root element of the SOAP body. Default value is root-element.

String arrayElementName

If the JSON input has an array as the first level element, this value will be the name of the XML tag that encloses each array element. Default value is element.

String namespacePrefix

Optional namespace prefix for the XML.

String namespaceURI

Optional namespace URI for the XML.

This API will convert the provided JSON message payload into a SOAP11 message payload.

convertToSOAP12

Parameters
XMessage message

Current message with JSON message payload.

This API will convert the provided JSON message payload into a SOAP12 message payload.

convertToSOAP12

Parameters
XMessage message

Current message with JSON message payload.

String rootElementName

Name of the XML root element of the SOAP body. Default value is root-element.

String arrayElementName

In case of JSON input has an array as the first level element, this value will be the name of the XML tag that encloses each array element. Default value is element.

String namespacePrefix

Optional namespace prefix for the XML.

String namespaceURI

Optional namespace URI for the XML.

This API will convert the provided JSON message payload into a SOAP12 message payload.

convertToXML

Parameters
XMessage message

Current message with JSON message payload.

This API will convert the provided JSON message payload into an XML message payload.

convertToXML

Parameters
XMessage message

Current message with JSON message payload.

String rootElementName

Name of the XML root element. Default value is root-element.

String arrayElementName

In case of JSON input has an array as the first level element, this value will be the name of the XML tag that encloses each array element. Default value is element.

String namespacePrefix

Optional namespace prefix for the XML.

String namespaceURI

Optional namespace URI for the XML.

This API will convert the provided JSON message payload into an XML message payload.

setAsJSONPayload

Parameters
XMessage message

Current message with JSON message payload.

This API will convert the current JSON message payload into a JSON format payload.

getUntypedMap

Parameters
XMessage message

Current message with JSON message payload.

boolean modifyPayload

If true, modifies the payload with the new untyped map.

Returns
Map<String, Object>

Untyped map that holds the content of the provided JSON message payload.

This API will return the current JSON message payload as an untyped Map.

getTypedObject

Parameters
XMessage message

Current message with JSON message payload.

Class<? extends T> clazz

Expected class type of the resulting message.

boolean modifyPayload

If true, modifies the payload with the new typed object.

Returns
<T> T

Instance of the specified class that holds the content of the provided JSON message payload.

This API will return the current JSON message payload as a typed object of the specified class.

addOrUpdateField

Parameters
XMessage message

Current message with JSON message payload.

String path

JSON path.

String key

Key of the field.

Object value

Value of the field.

This API will add or update the location pointed by the path, with the given key-value pair.

setField

Parameters
XMessage message

Current message with JSON message payload.

String path

JSON path.

String key

Key of the field.

Object value

Value of the field.

This API will set a new field to the location pointed by the path, with the given key-value pair.

renameField

Parameters
XMessage message

Current message with JSON message payload.

String path

JSON path.

String oldKeyName

Name of the old key to replace.

String newKeyName

New key name to assign.

This API will replace the old key name of the location pointed by the path, with the new key name.

removeField

Parameters
XMessage message

Current message with JSON message payload.

String path

JSON path.

String key

Key of the field.

This API will remove the given key at the location pointed by the path.

addElementToArray

Parameters
XMessage message

Current message with JSON message payload.

String path

JSON path.

String key

Key of the array field.

Object value

Value to be added.

This API will add a new value to the array specified by the key at the location pointed by the `path.

removeArrayElement

Parameters
XMessage message

Current message with JSON message payload.

String path

JSON path.

String key

Key of the array field.

int index

Index of the array element to be removed.

This API will remove the value at the index from the array, specified by the key at the location pointed by the path.

extractContent

Parameters
XMessage message

Current message with JSON message payload.

String path

JSON path.

Returns
Object

Content of the location pointed by the path.

This API will extract the content of the location pointed by the path.

extractTypedContent

Parameters
XMessage message

Current message with JSON message payload.

String path

JSON path.

Class<? extends T> clazz

Expected class type of the return message.

Returns
<T> T

An instance of the specified class that holds the content of the provided path of the JSON message payload.

This API will extract the content of the location pointed by the path as a typed object.

getJSONObject

Parameters
String jsonString

JSON string.

Returns
JSONObject

An object which contains the content of the JSON string provided.

This API will convert the provided JSON string into a JSON object.

validateJSONPath

Parameters
String path

JSON path.

Returns
boolean

true if the given path is a valid JSON path or false otherwise.

This API will return whether the given path is a valid JSON path.

JSON Path

JsonPath expressions always refer to a JSON structure in the same way as XPath expressions are used in combination with an XML document. The "root member object" in JsonPath is always referred to as $ regardless of an object or an array.

JsonPath expressions can use the dot–notation

$.store.book[0].title

or the bracket–notation

$['store']['book'][0]['title']

JsonPath should be expressed in bracket-notation, if field names included in the JsonPath contain space characters. Example $['book store']

Operators

Operator

Description

$

The root element to query. All path expressions start with this

@

The current node being processed by a filter predicate

*

Wildcard. Available anywhere a name or numeric is required

..

Deep scan. Available anywhere a name is required

.<name>

Dot-notated child

['<name>' (, '<name>')]

Bracket-notated child or children

[<number> (, <number>)]

Array index or indexes

[start:end]

Array slice operator

[?(<expression>)]

Filter expression. Expression must evaluate to a boolean value

Functions

Functions can be invoked at the tail end of a path. The input to a function is the output of the path expression. The function output is dictated by the function itself.

Operator

Description

min()

Provides the min value of an array of numbers

max()

Provides the max value of an array of numbers

avg()

Provides the average value of an array of numbers

stddev()

Provides the standard deviation value of an array of numbers

length()

Provides the length of an array

Filter Operators

Filters are logical expressions used to filter arrays. A typical filter would be [?(@.age > 18)] where @ represents the current item which is being processed. More complex filters can be created with logical operators && and ||. String literals must be enclosed by single or double quotes ([?(@.color == 'blue')] or [?(@.color == "blue")]).

Operator

Description

==

left is equal to right (note that 1 is not equal to '1')

!=

left is not equal to right

<

left is less than right

<=

left is less or equal to right

>

left is greater than right

>=

left is greater than or equal to right

=~

left matches regular expression [?(@.name =~ /foo.*?/i)]

in

left exists in right [?(@.size in ['S', 'M'])]

nin

left does not exists in right

subsetof

left is a subset of right [?(@.sizes subsetof ['S', 'M', 'L'])]

size

size of left (array or string) should match right

empty

left (array or string) should be empty

In this topic
In this topic
Contact Us