Implementing JSON-ISO and ISO-JSON message conversion
Here in this blog, we are going to learn how to implement JSON-ISO and ISO-JSON message conversion in IBM API Connect.
To implement JSON to ISO message conversion using IBM API Connect to Communicate with Backends like TCP/IP.
JSON Format:
JavaScript Object Notation, or JSON, is a lightweight data transfer format that is simple for both humans and machines to read, write, parse, and produce. It is commonly used for structuring and transmitting data between a server and a web application, as well as for storing configuration information and other structured data.
ISO Format:
The ISO format refers to date and time representation following the standards set by the International Organization for Standardization (ISO). ISO 8601 is the specific standard that outlines how dates and times should be formatted for consistency and clarity in various contexts, including computer systems, communication protocols, and data interchange.
Prerequisites:
- Requirements of the backend on message structure for both Request and Response.
- ISO Backend
- API Connect Environment for Implementation.
Implementation:
- Log on to the API Manager and Click On Develop, Click on Create API
- In this blog, I have used 2 gateway scripts to convert the message format from JSON to ISO and vice versa.
Sample Request:
{ "Name":"VyasavardhanRamagiri", "AccountNo": 6754399945672345, "bankCode": 788, "IFSC":"SBIN006765", "City":"Hyderabad" }
ISO Requirements:
[For characters padding is ‘ ‘ – space at the end of the value and for integers padding is ‘0’ – zero at the beginning of their values]
Frame request for TCP Backend as below:
VyasavardhanRamagiri 0000675439994567234 SBIN006765000000000200000
The same request is looped back from the backend then convert the ISO message to JSON Format as below.
{ "Name":"VyasavardhanRamagiri", "AccountNo": 6754399945672345, "IFSC":"SBIN006765", "City":"Hyderabad" }
For JSON to ISO Conversion, I have used the below functions in the gateway script:
- length()
- Fill()
For ISO to JSON Conversion, I have used the below functions in the gateway script:
- Slice()
- toString()
- JSON.stringify()
- Trim()
- parseInt()
These requirements were implemented using Gateway Script Action and respective Gateway Script code.
Testing:
JSON to ISO:
ISO to JSON:
Conclusion:
We can implement message conversion from JSON to ISO and vice versa using IBM API Connect.
Similarly, we can do it for XML also.