Jolt Transform JSON 具有动态值和 headers 的规格图

Jolt Transform JSON Spec map with dynamic values and headers

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

输入:

{
  "response": {
    "body": {
      "variables": {
        "swapOfferResult": {
          "value": {
            "EcomResponse": {
              "ConfigurationsResponse": {
                "productConfigurations": [
                  {
                    "productConfiguration": {
                      "productSpecification": {
                        "description": "Testing Sample 1",
                        "id": "1776911"
                      },
                      "productOffering": {
                        "description": "First sample description",
                        "name": "First sample",
                        "id": "1777341"
                      }
                    }
                  },
                  {
                    "productConfiguration": {
                      "productSpecification": {
                        "description": "Testing Sample 2",
                        "id": "247541"
                      },
                      "productOffering": {
                        "description": "Second sample description",
                        "name": "second sample",
                        "id": "735501"
                      }
                    }
                  },
                  {
                    "productConfiguration": {
                      "productSpecification": {
                        "description": "Testing Sample 3",
                        "id": "280801"
                      },
                      "productOffering": {
                        "description": "Third sample description",
                        "name": "Third sample",
                        "id": "735501"
                      }
                    }
                  }
                ]
              }
            }
          }
        }
      }
    }
  }
}

预期输出

需要在 header 部分包含名称、描述和 ID。非常感谢任何建议。 需要在 header 部分中包含名称、描述和 ID。非常感谢任何建议。

{
  "body": [
    {
      "id": "1777341",
      "description": "First sample description",
      "name": "First sample",
      "products": [
        {
          "id": "1776911",
          "description": "Testing Sample 1"
        }
      ]
    },
    {
      "id": "735501",
      "description": "second sample description",
      "name": "second sample",
      "products": [
        {
          "id": "247541",
          "description": "Testing Sample 2"
        },
        {
          "id": "280801",
          "description": "Testing Sample 3"
        }
      ]
    }
  ]
}

您可以使用以下连续规格

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": {
          "*": {
            "*": {
              "*": {
                "*": {
                  "*": {
                    "*": {
                      "*": {
                        "*": {
                          "productSpecification": {
                            "*": "@(2,productOffering.id).products.[&3].&",
                            "@(1,productOffering.description)": "@(2,productOffering.id).description",
                            "@(1,productOffering.name)": "@(2,productOffering.id).name"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "$": "&1.id",
        "*": "&1.&"
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": ""
    }
  },
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "*": "=recursivelySquashNulls"
    }
  },
  {
    "operation": "cardinality",
    "spec": {
      "*": {
        "products": "MANY",
        "*": "ONE"
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": "body[]"
    }
  }
]