【问题标题】:Jolt Transform JSON Spec map with dynamic values具有动态值的 Jolt Transform JSON Spec 映射
【发布时间】:2021-10-25 21:49:02
【问题描述】:

我需要在输入 JSON 下方进行转换以输出 JSON,但不确定如何为该输出编写规范。 比较 JOLT 转换中的字段值

这是输入:

{
  "body": {
    "productConfigurations": [
      {
        "productConfiguration": {
          "selected": true,
          "productSpecification": {
            "id": "1776911"
          },
          "productOffering": {
            "id": "1777341"
          }
        }
      },
      {
        "productConfiguration": {
          "selected": true,
          "productSpecification": {
            "id": "247541"
          },
          "productOffering": {
            "id": "735501"
          }
        }
      },
      {
        "productConfiguration": {
          "productSpecification": {
            "id": "280801"
          },
          "productOffering": {
            "id": "735501"
          }
        }
      }
    ]
  }
}

预期输出: 我需要在输入 JSON 下方进行转换以输出 JSON,并且不确定如何为该输出编写规范。比较 JOLT 转换中的字段值。

{
  "body": [
    {
      "id": "1777341",
      "products": [
        {
          "id": "1776911"
        }
      ]
    },
    {
      "id": "735501",
      "products": [
        {
          "id": "247541"
        },
        {
          "id": "280801"
        }
      ]
    }
  ]
}

【问题讨论】:

    标签: json jolt


    【解决方案1】:

    您可以使用以下连续移位转换

    [
      {
        "operation": "shift",
        "spec": {
          "*": {
            "*": {
              "*": {
                "*": {
                  "productSpecification": {
                    "id": "@(2,productOffering.&).products[].&"
                  }
                }
              }
            }
          }
        }
      },
      {
        "operation": "shift",
        "spec": {
          "*": {
            "$": "&1.id",
            "*": "&1.&"
          }
        }
      },
      {
        "operation": "shift",
        "spec": {
          "*": "body[]"
        }
      }
    ]
    

    主要思想是通过使用嵌套在"productSpecification" 标记对象中的"id": "@(2,productOffering.&).products[].&" 来确定@​​987654325@ 属性的常见id 值。

    【讨论】:

    • 当我们只有一个 productConfiguration 时,这将失败。
    • 是的,你是对的@Sandy。删除了多余的步骤(前第三个)。顺便说一句,您是否查看过为您的第二个问题提供的答案?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-25
    • 2019-02-26
    • 1970-01-01
    • 2022-10-06
    • 1970-01-01
    相关资源
    最近更新 更多