【问题标题】:Transform Array of objects with Jolt使用 Jolt 变换对象数组
【发布时间】:2018-03-23 11:21:51
【问题描述】:

我正在尝试使用 JOLT 将一组对象转换为输出 JSON,而其中没有包装键。

输入

{
  "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"
      } ]
    } ]
  }
}

请复制粘贴上面的INPUTOUTPUThere 如果我从输入中删除 emp 包装器,那么它的工作正常,但没有得到如何使用 emp 包装器获得相同的输出。

任何帮助表示赞赏。

【问题讨论】:

    标签: java transform jolt


    【解决方案1】:

    规格

    必须有第一个班次,通过“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[]": []
              }
            }
          }
        }
      }
    ]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-06
      • 1970-01-01
      • 1970-01-01
      • 2022-11-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-24
      相关资源
      最近更新 更多