Try this. Feel free to modify the script for your use case.
//Set the required libraries
var hm = require('header-metadata');
//Function for traversing through JSON tree
function convertKeys(obj) {
// Temporary object for storing traverse results
var tmpObj = {};
// Process array objects
if (Array.isArray(obj)) {
var arr = [];
// traverse through array content
for ( var i in obj) {
if (obj[i] !== null && typeof (obj[i]) == "object") {
arr.push(convertKeys(obj[i]));
} else {
arr.push(obj[i]);
}
}
tmpObj = arr;
}
// If not array, process other objects
else {
for ( var i in obj) {
var j = camelize(i);
if (obj[i] !== null && typeof (obj[i]) == "object") {
tmpObj[j] = convertKeys(obj[i]);
} else {
// If not array or object, assume that we have string, etc.
// value
tmpObj[j] = obj[i];
}
}
}
return tmpObj;
}
//Change to CamelCase
function camelize(str) {
return str.replace(/_/g, ' ').replace(/(?:^\w|[A-Z]|\b\w)/g, function(word, index) {
return index === 0 ? word.toLowerCase() : word.toUpperCase();
}).replace(/\s+/g, '');
}
// Parse incoming JSON payload
session.input.readAsJSON(function(error, reqBody) {
if (error) {
throw error;
} else {
// Use convert keys function call
var json = convertKeys(reqBody);
// Log entry for debug purposes
//console.log(JSON.stringify(json));
// Set content type to JSON
hm.current.set("Content-Type", "application/json");
// Send JSON request body to output
session.output.write(json);
}
});
#DataPower#Support#SupportMigration