Dear Arjun,
You can achieve your expected json format post xml-to-json policy, all you can place below gws code after convert policy
https://www.ibm.com/support/pages/how-convert-xml-json-format-other-badgerfish-using-datapower-gateway
var util = require('util');
var bfJson = apim.getvariable('message.body');
var plainJson = {};
convertBadgerfishToPlainJSON(bfJson, plainJson );
apim.setvariable('message.body', plainJson);
apim.output('application/json');
function convertBadgerfishToPlainJSON(inputDocument,outputDocument) {
for (var property in inputDocument) {
if (property.slice(0, 1) != '@') {
var propertyObj = inputDocument[property];
var i = property.indexOf(':');
if (i >= 0) {
property = property.slice(i + 1);
}
var type = util.safeTypeOf(propertyObj);
switch (type) {
case 'object':
if(propertyObj['$']) {
outputDocument[property] = propertyObj['$'];
} else {
outputDocument[property] = {};
convertBadgerfishToPlainJSON(propertyObj,outputDocument[property])
}
break;
case 'array':
outputDocument[property] = [];
convertBadgerfishToPlainJSON(propertyObj,outputDocument[property])
break;
default:
outputDocument[property] = propertyObj;
break;
}
}
}
}
------------------------------
Jayprakash Yadav
------------------------------
Original Message:
Sent: Tue March 08, 2022 03:38 AM
From: Arjun Pilli
Subject: Conversion from json to xml
Thank you, Steve. Will do. I will also request our IBM account manager to push this RFE.
------------------------------
Arjun Pilli
API Specialist
DSV
Johannesburg
+27 0840611655
Original Message:
Sent: Mon March 07, 2022 05:08 PM
From: Steve Linn
Subject: Conversion from json to xml
Hi Arjun,
Unfortunately, the XML2JSON policy in v10 does not have a "relaxed badgerfish" format option. The requirement is not new for sure, but I would suggest you open a request for enhancement at the Aha site https://integration-development.ideas.ibm.com/?project=APICONN. The more this need is socialized, the more likely it may eventually get some attention. In the meantime, the only option I have to provide is to run a "de-badgerfish" GatewayScript policy after the XML2JSON. I've provided that source in the forum before, but I'll post here as well.
Regards,
Steve
------------------------------
Steve Linn
Senior Consulting I/T Specialist
IBM
Original Message:
Sent: Fri March 04, 2022 04:02 AM
From: Arjun Pilli
Subject: Conversion from json to xml
Hi Steve,
Thank you for your suggestion on this matter. We are also seeing a similar issue while converting XML to JSON. by default its converting to Badgerfish format and there are no other options except v5 version format. I would like to know how do we select "relaxed badge fish" as you mentioned.
We are using v10 DataPower gateways.
------------------------------
Arjun Pilli
API Specialist
DSV
Johannesburg
+27 0840611655
Original Message:
Sent: Tue January 04, 2022 09:00 AM
From: Steve Linn
Subject: Conversion from json to xml
Hi Suraj,
The json-to-xml policy is very straight forward. One thing to do in APIC v10 is to parse the inbound JSON payload using a parse policy. The json-to-xml policy needs a parsed JSON document as input. The other suggestion is to set your conversion format to "relaxed badgerfish" which should take plain json such as
{"hello":"world"}
and convert it to
<hello>world</hello>
whereas the default type of badgerfish would fail as it would assume your input was of the badgerfish format
{"hello": {"$": "world"}}
Regards,
Steve
------------------------------
Steve Linn
Senior Consulting I/T Specialist
IBM
Original Message:
Sent: Thu December 30, 2021 09:50 AM
From: Suraj Sakpal
Subject: Conversion from json to xml
Hi,
How to use json-to-xml transform policy in ApicV10 to convert the content of our request body payload(Or any sample data in json format) from json to xml. Please provide us if any reference available for this conversion.
------------------------------
Thanks and regards,
Suraj
------------------------------