重新排列/互换嵌套的json数组键和值

时间:2019-05-21 12:44:50

标签: javascript arrays json reactjs

如何重新排列嵌套对象中的位置。      “ nextChildLogic”:“ AND”,键值需要移到“ nextChildLogic”键和值之后

Original input:

[
  {
    "bankId": 6111,
    "ruleSetId": 0,
    "name": "qewrf",
    "status": "Active",
    "defaultAuthMode": "otp",
    "description": "qweerrr",
    "rules": [
      {
        "conditions": [
          {
            "parameter": "Risk Engine Suggestion",
            "condition": "Equals",
            "value": "CRITICAL",
            "level": "first",
            "type": "condition"
          },
          {
            "level": "second",
            "type": "group",
            "nextChildLogic": "AND",
            "conditions": [
              {
                "parameter": "Merchant Name",
                "condition": "Equals",
                "value": "1212",
                "level": "second",
                "type": "condition"
              },
              {
                "logic": "AND",
                "parameter": "Risk Engine Score",
                "condition": "Equals",
                "value": "1222",
                "level": "second",
                "type": "condition"
              }
            ],
            "groupLogic": "OR"
          },
          {
            "logic": "OR",
            "parameter": "Merchant Name",
            "condition": "Equals",
            "value": "11111111111",
            "level": "first",
            "type": "condition"
          },
          {
            "level": "second",
            "type": "group",
            "nextChildLogic": "AND",
            "conditions": [
              {
                "parameter": "Merchant Name",
                "condition": "Contains",
                "value": "11111112",
                "level": "second",
                "type": "condition"
              },
              {
                "logic": "AND",
                "parameter": "Merchant Name",
                "condition": "Contains",
                "value": "1111111113",
                "level": "second",
                "type": "condition"
              }
            ],
            "groupLogic": "OR"
          }
        ],
        "modeOfAuth": "otp"
      }
    ],
    "user": "admin"
  }
]

预期输出:     我想使用循环相互交换键和值,并且我想要所需的输出,如

[
  {
    "bankId": 6111,
    "ruleSetId": 0,
    "name": "qewrf",
    "status": "Active",
    "defaultAuthMode": "otp",
    "description": "qweerrr",
    "rules": [
      {
        "conditions": [
          {
            "parameter": "Risk Engine Suggestion",
            "condition": "Equals",
            "value": "CRITICAL",
            "level": "first",
            "type": "condition"
          },
          {
            "level": "second",
            "type": "group",
            "nextChildLogic": "AND",
            "groupLogic": "OR"
            "conditions": [
              {
                "parameter": "Merchant Name",
                "condition": "Equals",
                "value": "1212",
                "level": "second",
                "type": "condition"
              },
              {
                "logic": "AND",
                "parameter": "Risk Engine Score",
                "condition": "Equals",
                "value": "1222",
                "level": "second",
                "type": "condition"
              }
            ],

          },
          {
            "logic": "OR",
            "parameter": "Merchant Name",
            "condition": "Equals",
            "value": "11111111111",
            "level": "first",
            "type": "condition"
          },
          {
            "level": "second",
            "type": "group",
            "nextChildLogic": "AND",
            "groupLogic": "OR"
            "conditions": [
              {
                "parameter": "Merchant Name",
                "condition": "Contains",
                "value": "11111112",
                "level": "second",
                "type": "condition"
              },
              {
                "logic": "AND",
                "parameter": "Merchant Name",
                "condition": "Contains",
                "value": "1111111113",
                "level": "second",
                "type": "condition"
              }
            ],

          }
        ],
        "modeOfAuth": "otp"
      }
    ],
    "user": "admin"
  }
]

所有“ groupLogic”键和值在“ conditions”:数组之前互换。

0 个答案:

没有答案