Using JSON in WebSphere Cast Iron, Part 1: Configuring Read JSON and Write JSON activities

IBM® WebSphere® Cast Iron introduced two activities, Read JSON and Write JSON to work with JSON data. Part 1 of this article series shows how to configure JSON handling activities to invoke JSON-based REST APIs and to create your own JSON-based REST APIs.

Rajath Ramesh (rajathr1@in.ibm.com), Software Engineer, IBM

Photo of Rajath RameshRajath Ramesh is a Software Engineer at the IBM India Software Labs. He started his career with IBM in 2010 as a developer in WebSphere Adapters and incubation projects. He is currently part of the WebSphere Cast Iron development team, specializing in Cast Iron Connectors, Cast Iron Studio, and the Connector Development Kit. He is a co-author of IBM Redbook: Getting Started with IBM WebSphere Cast Iron Cloud Integration.



Manjunatha D (manjunad@in.ibm.com), Software Engineer, IBM

Photo of Manjunatha DManjunatha D is a Software Engineer at the IBM India Software Labs. He works with the IBM WebSphere Adapters, IBM WebSphere Cast Iron, and IBM API Management teams.



31 July 2013

Also available in Chinese

Introduction

JavaScript Object Notation (JSON) is a text-based open standard designed for human-readable data interchange. It is derived from the JavaScript scripting language to represent simple data structures and associative arrays called objects. In the past, SaaS applications were largely used by enterprise customers. JSON is considered an efficient and effective way of representing data over HTTP. Earlier, almost all SaaS applications, which were exposing web services (transport data being SOAP message), have started to offer connectivity through REST API (transport data is JSON/XML).

WebSphere Cast Iron (hereafter called Cast Iron), being the major player in data integration and migration across on-premise and off-premise applications, works with XML and XML schemas. In WebSphere Cast Iron V6.3, two new activities are introduced to effectively enable orchestration building, which involves the use of JSON data - Read JSON and Write JSON. This article describes various ways to configure Read JSON and Write JSON activities to help you effectively handle JSON data.


Overview of the Read JSON activity

The Read JSON activity is used to convert a string in JSON format to an XML variable, which you can use to map across activities within an orchestration. For this, you need an XML schema that will be used for conversion from a JSON string to an XML variable. During configuration, you can generate the XML schema (output schema) using a sample JSON or XML string, or you can use the XML schema available in the studio project in the WSDL or XML Schema sections described in the next section.

Configuring the Read JSON activity

In this section, you will learn how to configure the Read JSON activity.

  1. Drag and drop the Read JSON activity to the workspace and click Configure in the "Checklist" pane, as shown in Figure 1.
    Figure 1. Read JSON Configure window
    Read JSON Configure window
  2. You can configure the XML schema either by generating it using the JSON/XML string, or you can specify an XML schema present in the WSDL/XML schemas. This XML schema is the XML schema of the Map Outputs XML variable.
    1. Generate the XML schema from JSON/XML string. Select the Use JSON or XML Message type from the Configure window, as shown in Figure 2.
      Figure 2. Select Message Type – Use JSON or XML Message
      Select Message Type – Use JSON or XML Message

      Then copy the JSON or XML message into the text area and click Generate Output Map, as shown in Figure 3. It generates the Read JSON output parameters (XML schema), which you can see in Map Outputs.

      Figure 3. Sample JSON or XML message to generate output schema
      Sample JSON or XML message to generate output schema

      Optionally, you can configure the name of the root element of the XML schema, generated from the sample JSON /XML. By default, the root element name is "Json" as shown in Figure 4.

      Figure 4. Virtual root configuration
      Virtual root configuration
    2. Select an existing XML schema. Click the Select XML Schema option from the Configure window as shown in Figure 5.
      Figure 5. Select Message Type – XML Schema
      Select Message Type – XML Schema

      Click the Select XML Schema button (Figure 6) to browse and select the XML schema to parse against during the runtime, and click OK.

      Figure 6. Select XML Schema
      Select XML Schema
  3. You can also configure the reading of the data passed into the JSON Text input parameter at runtime by selecting one of the options:
    1. Select the Data is text-Needs no decoding option (Figure 7) if the incoming JSON data is text and does not need decoding.
      Figure 7. Incoming data requires no decoding
      Incoming data requires no decoding
    2. Select the Decode data using encoding type option (Figure 8) if the incoming JSON data is binary data that needs to be decoded using the specified encoding type. Set the encoding type by selecting an encoding type from the drop-down list or specify your encoding type in the text box.
      Figure 8. Select encoding type to decode
      Select encoding type to decode

Overview of the Write JSON activity

The Write JSON activity accepts XML data as an XML variable and outputs the string in JSON format. You can use this JSON string as required in the orchestration design.

Configuring the Write JSON activity

  1. Drag and drop the Write JSON activity to a workspace and click Configure from the Checklist pane, as shown in Figure 9.
    Figure 9. Write JSON Configure window
    Write JSON Configure window
  2. You can configure the XML schema either by generating it by using a JSON/XML string, or you can specify an XML schema present in the WSDL/XML Schemas. This XML schema is the XML schema of the Map Inputs XML variable.
    1. Generate the XML schema from the JSON/XML string. Select Use JSON or XML Message as the message type from the Configure window, as shown in Figure 10.
      Figure 10. Select the Message Type – Use JSON or XML Message
      Select the Message Type – Use JSON or XML Message

      Copy the JSON or XML message into the text area and click Generate Map. It generates the Write JSON input parameters (XML schema), which is shown in Map Inputs.

    2. Select the existing XML schema. Click the Select XML Schema option from the Configure window as shown in Figure 11.
      Figure 11. Select Message Type – Select XML Schema
      Select Message Type – Select XML Schema

      The "Select XML Schema" option is activated (Figure 12). Click the button to browse for the XML schema, select the XML schema, and click OK.

      Figure 12. Select XML Schema
      Select XML Schema
  3. Not all JSON messages contain a root node by default. In such cases, a virtual node is added to the XML schema representation and the actual data are child elements of the virtual root node. You can specify a name for the virtual root node in the "Root Element Name" text box. Select the Remove Root Element checkbox (Figure 13) so that the virtual root node is removed while processing.
    Figure 13. Virtual Root Configuration – Write JSON
    Virtual Root Configuration – Write JSON
  4. You can also configure how to read the data passed into the JSON Text input parameter at runtime by selecting one of the appropriate options:
    1. Select the Data is text-Needs no decoding option (Figure 14) if the incoming data is text and does not require decoding.
      Figure 14. Incoming data requires no decoding
      Incoming data requires no decoding
    2. Select the Decode data using encoding type option (Figure 15) if the incoming data is binary that needs to be decoded using the specified encoding type. Set the encoding type by selecting an encoding type from the drop-down list or specify your encoding type in the text box.
      Figure 15. Select encoding type to decode
      Select encoding type to decode

In Part 2 of this series, you will learn how to build an orchestration that invokes JSON-based REST APIs exposed by Salesforce.com to create an account.


Conclusion

This article described how to configure Read JSON and Write JSON activities and showed how you can effectively handle JSON data while building an orchestration in WebSphere Cast Iron. In Part 2 of this series, you will learn how to build an orchestration that invokes JSON-based REST APIs exposed by Salesforce.com to create an account. In Part 3, you will learn how to design an orchestration that is exposed as a JSON-based API.

Acknowledgments

The authors would like to thank Raghavendra K. Neelekani for reviewing and providing valuable suggestions for this article series.

Resources

Learn

Discuss

Comments

developerWorks: Sign in

Required fields are indicated with an asterisk (*).


Need an IBM ID?
Forgot your IBM ID?


Forgot your password?
Change your password

By clicking Submit, you agree to the developerWorks terms of use.

 


The first time you sign into developerWorks, a profile is created for you. Information in your profile (your name, country/region, and company name) is displayed to the public and will accompany any content you post, unless you opt to hide your company name. You may update your IBM account at any time.

All information submitted is secure.

Choose your display name



The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerWorks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

Required fields are indicated with an asterisk (*).

(Must be between 3 – 31 characters.)

By clicking Submit, you agree to the developerWorks terms of use.

 


All information submitted is secure.

Dig deeper into WebSphere on developerWorks


static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=WebSphere
ArticleID=939292
ArticleTitle=Using JSON in WebSphere Cast Iron, Part 1: Configuring Read JSON and Write JSON activities
publish-date=07312013