繁体   English   中英

使用Jolt变换对象数组

[英]Transform Array of objects with Jolt

我正在尝试使用JOLT将一个对象数组转换为不带包装键的输出JSON。

INPUT

{
  "emps": [
    {
      "emp": {
        "empId": "2A68",
        "emailAddress": "abc@xyz.com",
        "name": "abc",
        "userId": "82869",
        "userType": "none",
        "phoneNumber": "1234",
        "rank": "2"
      }
    }
  ]
}

我尝试过的规格

[
  {
    "operation": "shift",
    "spec": {
      "emps": {
        "*": {
          "empId": "data.result[&1].emps[&1].empId",
          "name": "data.result[&1].emps[&1].name",
          "phoneNumber": "data.result[&1].emps[&1].phone",
          "emailAddress": "data.result[&1].emps[&1].email"
        }
      }
    }
  },
  {
    "operation": "default",
    "spec": {
      "data": {
        "result[]": {
          "*": {
            "emps[]": []
          }
        }
      }
    }
  }
]

预期的输出

{
  "data" : {
    "result" : [ {
      "emps" : [ {
        "empId" : "2A68",
        "name" : "abc",
        "phone" : "1234",
        "email" : "abc@xyz.com"
      } ]
    } ]
  }
}

在此处复制并粘贴上面的INPUTOUTPUT 如果我从输入中删除emp包装器,则其工作正常,但没有得到如何使用emp包装器获得相同的输出。

任何帮助表示赞赏。

规格

必须先进行移位,然后依次通过“ emps”,数组和“ emp”对象。

[
  {
    "operation": "shift",
    "spec": {
      "emps": {
        "*": {
          "emp": {
            "empId": "data.result[0].emps[&2].empId",
            "name": "data.result[0].emps[&2].name",
            "phoneNumber": "data.result[0].emps[&2].phone",
            "emailAddress": "data.result[0].emps[&2].email"
          }
        }
      }
    }
  },
  {
    "operation": "default",
    "spec": {
      "data": {
        "result[]": {
          "*": {
            "emps[]": []
          }
        }
      }
    }
  }
]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM