Jolt 变换嵌套 json 数组

Jolt transform nested json array

我 json 其中包括多个产品,每个产品都有多个变体详细信息。 使用 jolt 我只需要来自输入 json 的几个字段,遵循与输入 json 几乎相同的结构。 我成功地迭代了产品,但是当我尝试迭代每个产品变体时,我没有得到所需的输出。

Input.json

{
  "products": [
    {
      "id": 6635020550275,
      "title": "UAT-9122021",
      "handle": "uat-9122021",
      "body_html": "UAT-9122021",
      "published_at": "2021-09-13T20:56:30+10:00",
      "created_at": "2021-09-13T20:56:28+10:00",
      "updated_at": "2021-09-13T21:05:17+10:00",
      "vendor": "Britax Test",
      "product_type": "",
      "tags": [],
      "variants": [
        {
          "id": 39516385214595,
          "title": "Default Title",
          "option1": "Default Title",
          "option2": null,
          "option3": null,
          "sku": "UAT-9122021",
          "requires_shipping": true,
          "taxable": true,
          "featured_image": null,
          "available": true,
          "price": "19.30",
          "grams": 0,
          "compare_at_price": null,
          "position": 1,
          "product_id": 6635020550275,
          "created_at": "2021-09-13T20:56:29+10:00",
          "updated_at": "2021-09-13T21:04:45+10:00"
        }
      ],
      "images": [],
      "options": [
        {
          "name": "Title",
          "position": 1,
          "values": [
            "Default Title"
          ]
        }
      ]
    },
    {
      "id": 6632446787715,
      "title": "UAT-992021",
      "handle": "uat-992021",
      "body_html": "UAT-992021",
      "published_at": "2021-09-09T22:53:05+10:00",
      "created_at": "2021-09-09T22:53:04+10:00",
      "updated_at": "2021-09-09T23:05:26+10:00",
      "vendor": "Britax Test",
      "product_type": "",
      "tags": [],
      "variants": [
        {
          "id": 39511546462339,
          "title": "Default Title",
          "option1": "Default Title",
          "option2": null,
          "option3": null,
          "sku": "UAT-992021",
          "requires_shipping": true,
          "taxable": true,
          "featured_image": null,
          "available": true,
          "price": "35.50",
          "grams": 0,
          "compare_at_price": null,
          "position": 1,
          "product_id": 6632446787715,
          "created_at": "2021-09-09T22:53:04+10:00",
          "updated_at": "2021-09-09T23:04:40+10:00"
        }
      ],
      "images": [],
      "options": [
        {
          "name": "Title",
          "position": 1,
          "values": [
            "Default Title"
          ]
        }
      ]
    }
  ]
}

这里是Spec.json

[
  {
    "operation": "shift",
    "spec": {
      "products": {
        "*": {
          "created_at": "productDoc[&1].createdDateTime",
          "id": "productDoc[&1].id",
          "variants": {
            "*": {
              "id": "productDoc[&1].variants.[&1].ecommVariantId",
              "created_at": "productDoc[&1].variants.[&1].createdDateTime"
            }
          }
        }
      }
    }
  }
]

我想要的预期输出。

{
    "productDoc": [{
        "createdDateTime": "2021-09-13T20:56:28+10:00",
        "id": 6635020550275,
        "variants": [{
            "ecommVariantId": [39516385214595],
            "createdDateTime": ["2021-09-13T20:56:29+10:00"]
        }]
    }, 
    {
        "createdDateTime": "2021-09-09T22:53:04+10:00",
        "id": 6632446787715,
        "variants": [{
            "ecommVariantId": [39516385214595],
            "createdDateTime": ["2021-09-09T22:53:04+10:00"]
        }]
    }]
}

我现在得到的实际输出。

{
  "productDoc" : [ {
    "createdDateTime" : "2021-09-13T20:56:28+10:00",
    "id" : 6635020550275,
    "variants" : [ {
      "ecommVariantId" : [ 39516385214595, 39511546462339 ],
      "createdDateTime" : [ "2021-09-13T20:56:29+10:00", "2021-09-09T22:53:04+10:00" ]
    } ]
  }, {
    "createdDateTime" : "2021-09-09T22:53:04+10:00",
    "id" : 6632446787715
  } ]
}

不要将 [&1] 与嵌套的 productDoc 一起使用。 使用[&3]因为实际产品达到3级。

[
  {
    "operation": "shift",
    "spec": {
      "products": {
        "*": {
          "created_at": "productDoc[&1].createdDateTime",
          "id": "productDoc[&1].&",
          "variants": {
            "*": {
              "id": "productDoc[&3].&2.[&1].ecommVariantId",
              "created_at": "productDoc[&3].&2.[&1].createdDateTime"
            }
          }
        }
      }
    }
  }
]