简体   繁体   English

嵌套颠簸转换不起作用

[英]Nested Jolt Transformation not working

{
    "items": [
        {
            "itemId": 1,
            "itemName": "OKRA",
            "stock": [
                {
                    "stock": 50,
                    "salePrice": 150
                },
                {
                    "stock": 100,
                    "salePrice": 75
                }
            ]
        },
        {
            "itemId": 2,
            "itemName": "CUCUMBER",
            "stock": [
                {
                    "stock": 100,
                    "salePrice": 10
                },
                {
                    "stock": 200,
                    "salePrice": 5
                }
            ]
        }
    ],
    "count": 2,
    "total_records": 428,
    "current_page": 1,
    "per_page": 2,
    "total_pages": 215
}

Excepted Output should be 预期输出应为

{
    "items": [
        {
            "itemId": 1,
            "itemName": "OKRA",
            "salePrice": 150,
            "stock": 50
        },
        {
            "itemId": 1,
            "itemName": "OKRA",
            "salePrice": 75,
            "stock": 100
        },
        {
            "itemId": 2,
            "itemName": "CUCUMBER",
            "salePrice": 10,
            "stock": 100
        },
        {
            "itemId": 2,
            "itemName": "CUCUMBER",
            "salePrice": 5,
            "stock": 200
        }
    ]
}

My spec file 我的规格文件

[
  {
    "operation": "shift",
    "spec": {
      "items": {
        "*": {
          "stock": {
            "*": {
              "@2": "itemsArray[]",
              "@": "stockArray[]"
            }
          }
        }
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "itemsArray": {
        "*": { // bizArray index
          "itemId": "items[&1].itemId",
          "itemName": "items[&1].itemName",
          "stock": "items[&1].stock[&1].stock",
          "salePrice": "[&1].stock[&1].salePrice"
        }
      }
    }
  }
]

Anyone help me to get the Excepted output.I am new to JOLT. 任何人都可以帮助我获得Excepted输出。我是JOLT的新手。

[
  {
    "operation": "shift",
    "spec": {
      "items": {
        "*": {
          "stock": {
            "*": {
              "@2": "itemsArray[]",
              "@": "stockArray[]"
            }
          }
        }
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "itemsArray": {
        "*": {
          "itemId": "items[&1].itemId",
          "itemName": "items[&1].itemName"
        }
      },
      "stockArray": {
        "*": {
          "stock": "items[&1].stock",
          "salePrice": "items[&1].salePrice"
        }
      }
    }
  }
]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM