JSFiddle - React, Tailwind, and code Playground

by Taleeb Anwar

JavaScript

var elementsToConvertToString = ["elementValue1", "elementValue2", "elementValue3", "elementValue4", "elementValue6", "elementValue7", "elementValue8", "elementValue9", "elementValue13", "elementValue17", "elementValue18", "elementValue19"]
var twoDecimalPlaces = ["elementValue10", "elementValue15"]
var fourDecimalPlaces = ["elementValue14"]

function transform(message, output) {
  var notifications = message.request.input.notifications
  notifications = traverseAndUpdate(notifications);
  if (notifications.email == "[email protected]") {
    notifications.email = "[email protected]";
  }
  message.notifications = [];

  message.notifications.push(notifications);

  output["notifications"] = message["notifications"];
  console.log(output);
}

function traverseAndUpdate(jsonObj, key) {
  if (jsonObj != null && typeof jsonObj == "object") {
    for (var key in jsonObj) {
      value = jsonObj[key];
      if (value != null) {
        jsonObj[key] = traverseAndUpdate(value, key);
      }
    }
  } else if (jsonObj != null && typeof(jsonObj) == "number") {
    if (key != null && elementsToConvertToString.indexOf(key) > -1) {
      return jsonObj.toString();
    } else {
      return jsonObj;
    }
  } else {
    return jsonObj;
  }
  return jsonObj;
}
var msg = {
  "request": {
    "@context": "notifications",
    "@type": "sendNotifications",
    "@correlationId": "f2203d84-9313-4156-a1d6-afe094511a3a",
    "input": {
      "notifications": {
        "messageId": "b31ec7b7-1d4b-4711-81e4-36851d58ee00",
        "messageType": "ClpFullfilmentNot",
        "channel": "Email",
        "source": "CLP",
        "references": {
          "id": null,
          "type": null
        },
        "email": "[email protected]",
        "context": {
          "elementValue1": "Temporary Overdraft Request",
          "elementValue2": null,
          "elementValue3": "SAHAGUN GROUP TRUST",
          "elementValue4": 2000496379,
          "elementValue5":...