Table of Contents

Search

  1. Preface
  2. Web Services
  3. SOAP Web Services
  4. WSDL Data Object
  5. Schema Object
  6. How to Create a SOAP Web Service
  7. Operation Mappings
  8. Parsing Web Service SOAP Messages
  9. Generating Web Service SOAP Messages
  10. Web Service Consumer Transformation
  11. REST Web Services
  12. How to Create a REST Web Service
  13. REST Web Service Consumer Transformation
  14. REST Web Service Consumer Transformation Use Cases
  15. REST and SOAP Web Service Administration
  16. Datatype Compatibility

Web Services Guide

Web Services Guide

How to Parse Request and Response Messages in JSON Format

How to Parse Request and Response Messages in JSON Format

To set up the REST Web Service Consumer transformation to parse a JSON response, set the log level to Verbose Data in the Developer tool preferences. Open the verbose data log and copy the response to an XML file. Import the XML file as a schema object and use the schema to create the transformation. After you create the transformation, configure the transformation to receive a JSON response.

Step 1. Set the Log Level to Verbose Data.

To set the log level to Verbose Data, complete the following steps:
  1. In the Developer tool, click
    Window > Preferences
    .
  2. On the left-hand side of the
    Preferences
    window, click Run Configurations > Mapping.
  3. On the right-hand side, select the
    Advanced
    tab.
  4. For the property
    Override tracing level
    , select
    Verbose Data
    .
    This image shows the Advanced tab of the mapping configuration properties. The Advanced tab includes the property Override tracing level. For the property Override tracing level, Verbose Data is selected.
  5. Open the verbose data log.
  6. Search for
    HTTP Response BODY: <?xml
  7. Copy the data between <xmlRoot> and </xmlRoot> and save the data as an XML file.
  8. Import the XML file as a schema object in the Developer tool.

Step 2. Use the Schema to Create a REST Web Service Consumer Transformation.

To use the schema to parse the data that the REST Web Service Consumer transformation receives, complete the following steps:
  1. In the Developer tool mapping editor, scroll down in the mapping palette to locate the REST Web Service Consumer transformation and drag it into the mapping.
  2. Enter a name for the transformation.
  3. Select an HTTP method.
  4. Click
    Next
    .
  5. To define the method input, select
    Create as empty
    or
    Create from an element in a Schema Object
    . When you define the method input, you define the method input definition and the input mapping.
  6. Click
    Next
    .
  7. To define the method output, select
    Create from an element in a Schema object
  8. Click
    Browse
    .
  9. Select the element
    xmlRoot
    .
    The following image shows how the element xmlRoot might appear:
    This image shows the dialog box that prompts you to select a schema element. It shows the schema objects stored in the Model repository and the parent element of the schema.
  10. Configure the output mapping. If a parent element contains child elements, you must map the child elements manually. Drag the parent and child element groups from the Method output definition area to the Ports area.
    You might have a mapping that looks like the following image:
    This image shows a sample output mapping. The Method output definition area is on the left and the Ports area is on the right. The elements in the Method output definition area are mapped as corresponding elements in the Ports area.
  11. Configure the REST Web Service Consumer transformation properties. For the property
    Output Format
    , specify
    JSON
    .
  12. Run the transformation.
    The following image shows an example of a response that you might receive:
    This image shows a response that you might receive. Each parent element is separated into a group that consists of its child elements. The data is parsed according to the element hierarchy.
    Note that the data in the response is parsed to form groups that consist of a parent element and nested child elements.

0 COMMENTS

We’d like to hear from you!