Enhanced Public Service for JSON Conversion in webMethods Integration Server 10.15
Tags: webmethods, integration, json, guide
Published: 2023-03-13 13:32:15

---
title: Enhanced Public Service for JSON Conversion in webMethods Integration Server 10.15
published: true
date: 2023-02-23 07:29:11 UTC
tags: webMethods, integration, json, guide
canonical_url: https://tech.forums.softwareag.com/t/enhanced-public-service-for-json-conversion-in-webmethods-integration-server-10-15/275070
---

 

\*products versions - **webMethods Integration Server 10.15**

Is there is a service to enhance the JSON conversion? Yes there is a new service introduced in 10.15, the “pub.json:jsonToDocument” service. This service is an improved version of the existing services “pub.json:jsonStringToDocument” and “pub.json:jsonStreamToDocument”.

## **How pub.json:jsonToDocument is different from the existing services?**

Let’s see how pub.json:jsonToDocument is different from the existing services:,  
• The “pub.json:jsonToDocument” accepts both JSON stream and JSON string as an input.  
• This service provides two options to convert a JSON input to a document.

- By providing the document as a reference.
- By choosing a datatype to which you want to convert the input.  
• When you convert the JSON input to an IData document by providing the reference document, the “pub.json:jsonToDocument” service accepts all types of documents , whereas the existing services can accepts only the JSON schema documents as a reference.  
• The “pub.json:jsonToDocument” service has an intelligence to handle the duplicate fields  
• If any field in the reference document is mentioned as date, then this service can convert that specific string field into Date.  
• For more information on the formats, see BIS guide [MR1]  
Link: [BIS Guide](https://documentation.softwareag.com/webmethods/integration_server/pie10-15/webhelp/pie-webhelp/index.html#page/pie-webhelp%2Fpub.json_3ajsonToDocument.html%23wwconnect_header)

Note: When documentTypeName is provided, the service ignores the following inputs  
• decodeIntegerAs  
• decodeDecimalAs  
• decodeBooleanAs

## **How to use pub.json:jsonToDocument?**

Let’s see the usage of the “pub.json:jsonToDocument” service with some examples.  
This following diagram represents the input parameters in “pub.json:jsonToDocument” service

[![image](https://global.discourse-cdn.com/techcommunity/optimized/3X/2/4/24caa9ed930dbdcd470d140a7ad2e9309792f485_2_690x492.png)](https://global.discourse-cdn.com/techcommunity/original/3X/2/4/24caa9ed930dbdcd470d140a7ad2e9309792f485.png "image")
  
**Case 1:** Convert a JSON input to an IData Document with “pub.json:jsonToDocument” service by referring the reference document

- Create a flow service and invoke the “pub.json:jsonToDocument” service
- Refer the reference document against “documentTypeName”
- Execute the service.

[![image](https://global.discourse-cdn.com/techcommunity/optimized/3X/3/b/3b9b1695d27acf3efb0d1f4ca0135bd589a7a13f_2_690x367.png)](https://global.discourse-cdn.com/techcommunity/original/3X/3/b/3b9b1695d27acf3efb0d1f4ca0135bd589a7a13f.png "image")

Provide the JSON input as:

```
{
"employeeName": "Sam",
"employeeAge": 28,
"employeeJoiningDate": "2022-10-10",
"employeeDesignation": "Software Engineer"
}

```

Following is a sample reference document:

[![image](https://global.discourse-cdn.com/techcommunity/optimized/3X/5/8/588d4ce4a9f15a53a0e981a8de1b31f1a12a6710_2_690x465.png)](https://global.discourse-cdn.com/techcommunity/original/3X/5/8/588d4ce4a9f15a53a0e981a8de1b31f1a12a6710.png "image")

Now, in the output, all the fields are converted to the respective types mentioned in the reference document.

[![image](https://global.discourse-cdn.com/techcommunity/optimized/3X/d/7/d705c9afe6f92390e5c328baec365fa1c1c07184_2_690x289.png)](https://global.discourse-cdn.com/techcommunity/original/3X/d/7/d705c9afe6f92390e5c328baec365fa1c1c07184.png "image")

Note: Here the “employeeJoiningDate” JSON input String field is converted to Date in the output because the reference document has a reference to date type.

**Case 2:** Convert a JSON input to an IData by referring the document, where input has a duplicate field:

When there is a duplicate field in the JSON Input the “pub.json:jsonToDocument” service throws the an exception .

Provide the JSON input as:  
Contains employeeAge as duplicate field.

```
{
"employeeName": "Sam",
"employeeAge": 28,
"employeeAge": 28,
"employeeJoiningDate": "2022-10-10",
"employeeDesignation": "Software Engineer"
}

```

Now in the output we can notice an error, stating that duplicate field is not allowed, and there is a parser exception.

[![image](https://global.discourse-cdn.com/techcommunity/optimized/3X/2/b/2b0a44c20eb79be8b69ab7197c4bb9129c5434cb_2_690x295.png)](https://global.discourse-cdn.com/techcommunity/original/3X/2/b/2b0a44c20eb79be8b69ab7197c4bb9129c5434cb.png "image")

**Case 3:** Convert a JSON input to an IData by referring the document, where reference document has a duplicate field:

When there is a duplicate field in the reference document the conversion happens by considering the first suitable match, In this case the first duplicate field is of type int and the second one is of type long, Therefore the JSON input conversion considers the int type as it is the first suitable match.

Following is a sample reference document that has “employeeAge” as a duplicate field:

[![image](https://global.discourse-cdn.com/techcommunity/optimized/3X/6/f/6f95a706bed9474330c4df8d4895bdad90843437_2_690x416.png)](https://global.discourse-cdn.com/techcommunity/original/3X/6/f/6f95a706bed9474330c4df8d4895bdad90843437.png "image")

Provide the JSON input as:

```
{
"employeeName": "Sam",
"employeeAge": 28,
"employeeJoiningDate": "2022-10-10",
"employeeDesignation": "Software Engineer"
}

```

Now the output gets generated by considering the first suitable match, that is, the Int type.

[![image](https://global.discourse-cdn.com/techcommunity/optimized/3X/5/f/5feca1a07db089b63361fc2661a78c02c517180d_2_690x357.png)](https://global.discourse-cdn.com/techcommunity/original/3X/5/f/5feca1a07db089b63361fc2661a78c02c517180d.png "image")

**Case 4:** Convert the a JSON input to an IData by providing the decodeAs fields:

Provide the JSON input as:

```
{
"employeeName" : "Sam",
"employeeAge" : 28,
"employeeJoiningDate": "2022-10-10",
"employeeDesignation" : "Software Engineer",
"isReferral" : true
}

```

Here the decodeIntegerAs field is set to String and the decodeBooleanAs field is set to Boolean

[![image](https://global.discourse-cdn.com/techcommunity/optimized/3X/f/c/fc71e3ef002fa9241b8bcc0825003a120258b37e_2_616x500.png)](https://global.discourse-cdn.com/techcommunity/original/3X/f/c/fc71e3ef002fa9241b8bcc0825003a120258b37e.png "image")

[![image](https://global.discourse-cdn.com/techcommunity/optimized/3X/e/2/e29b1bb6b21bb3b97bcf9950a1b9ddeafd228b9f_2_669x500.png)](https://global.discourse-cdn.com/techcommunity/original/3X/e/2/e29b1bb6b21bb3b97bcf9950a1b9ddeafd228b9f.png "image")

Now the output contains all the integers in the JSON input as String and all the Boolean values in the input as Boolean.

[![image](https://global.discourse-cdn.com/techcommunity/optimized/3X/8/a/8a06328d38d5f8541dc431ff5fece12cdc03e6bd_2_690x295.png)](https://global.discourse-cdn.com/techcommunity/original/3X/8/a/8a06328d38d5f8541dc431ff5fece12cdc03e6bd.png "image")


[Read full topic](https://tech.forums.softwareag.com/t/enhanced-public-service-for-json-conversion-in-webmethods-integration-server-10-15/275070)