嵌套的Jolt转换不起作用

时间:2017-04-18 07:21:02

标签: java jolt

{
    "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
}

例外输出应为

{
    "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
        }
    ]
}

我的规范文件

[
  {
    "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"
        }
      }
    }
  }
]

任何人都可以帮助我获得Excepted输出。我是JOLT的新手。

1 个答案:

答案 0 :(得分:0)

[
  {
    "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"
        }
      }
    }
  }
]