Retrieve Attributes with JSON Path

Overview

JSON Path is an XPath like query language for JSON (JavaScript Object Notation) that enables you to select nodes in a JSON document. The Retrieve Attributes with JSON Path filter enables you to retrieve specified message attributes from a JSON message using JSON Path expressions.

For more details on JSON Path, see http://code.google.com/p/jsonpath/.

Configuration

Configure the following fields on the Retrieve Attributes with JSON Path filter screen:

Name:

Enter an appropriate name for this filter.

Extract attributes using the following JSON Path expressions:

Specify the list of attributes for the API Gateway to retrieve using appropriate JSON Path expressions. All attribute values are stored in the attribute.lookup.list message attribute.

To add an attribute to the list, click the Add button, and enter the following values in the dialog:

  • Attribute name:

    Enter the message attribute name that you wish to extract using JSON Path (for example, bicycle.price).

  • JSON Path Expression:

    Enter the JSON Path expression that you wish to use to extract the message attribute (for example, $.store.bicycle.price). The Policy Studio prompts if you enter an unsupported JSON Path expression.

  • Unmarshal as:

    Enter the data type to unmarshal the message attribute value as (defaults to java.lang.String).

  • Fail if JSON Path Fails:

    Select whether the filter should fail if the specified JSON Path expression fails. This option is not selected by default.

[Note] Note

If no attributes are specified, the API Gateway retrieves all the attributes in the message and sets them to the attribute.lookup.list attribute.

JSON Path Examples

The following are some examples of using the Retrieve Attributes with JSON Path filter to retrieve data from a JSON message.

Retrieving Attributes

The following example retrieves three different data items from the JSON message and stores them in the specified message attributes as strings:

Retrieve Attribute with JSON Path Expression

When the extracted attributes are added to the content.body message attribute, the following example shows the corresponding request and response message in Oracle API Gateway Explorer:

Retrieved Attribute

Retrieving Multiple Attributes in a List

The following example retrieves all the authors from the JSON message and stores them in the specified message attribute as a List:

Retrieve Attribute List using JSON Path Expression

The following example shows the corresponding request and response in Oracle API Gateway Explorer:

Retrieved Attribute List