【问题标题】:Jolt transformation array data颠簸变换数组数据
【发布时间】:2021-02-01 21:37:58
【问题描述】:

我想像这样使用 JOLT 转换 JSON:

Input: {
    "array": [
       "1","2","3","4"
    ],
    "array2": [
       {  
          "something": "123",
          "something1": "Plane"
       },
       {
          "something3": "567",
          "something4": "Car"
       }
    ]
}

转换为以下格式,正如您从输出中看到的那样,我需要两个数组中的数据来匹配确切的参数名称,而不是像第一个那样为空或像第二个那样存在参数名称。

Output: {
    "one_array": [
      {
       "code": "1", 
       "description": "", 
      },
      {
       "code": "2", 
       "description": "", 
      },
      {
       "code": "3", 
       "description": "", 
      },
      {
       "code": "4", 
       "description": "", 
      }
], "other_array": [
      {
          "id": "123",
          "type": "Plane"
      }, 
      {
          "id": "567",
          "type": "Car"
      }
]
}

非常感谢一些澄清

【问题讨论】:

    标签: json transform jolt


    【解决方案1】:

    您可以使用 2 个shift 操作和default 操作来实现此目的,如下所示。

    [
      {
        "operation": "shift",
        "spec": {
          "array": {
            "*": {
              "@": "one_array[&].id"
            }
          },
          "array2": {
            "*": {
              "*": {
                "@": "tmp_array[&2]"
              }
            }
          }
        }
       },
      {
        "operation": "shift",
        "spec": {
          "one_array": "one_array",
          "tmp_array": {
            "*": {
              "0": "other_array[&1].id",
              "1": "other_array[&1].type"
            }
          }
        }
       },
      {
        "operation": "default",
        "spec": {
          "one_array[]": {
            "*": {
              "description": ""
            }
          }
        }
       }
    ]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-01-08
      • 2022-01-07
      • 2019-02-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多