Jolt 从数组到对象的转换并提取值

Jolt trasform from array to object and extract value

我需要对下面的示例执行 Jolt 转换 json:

输入

[
  {
    "DOCUMENT_HEADER_ID": "29120",
    "Descrizione": "GAS",
    "PrezzoTotale": "8.51"
  },
  {
    "DOCUMENT_HEADER_ID": "29120",
    "Descrizione": "IMPOSTE",
    "PrezzoTotale": "7.25"
  },
  ...
]

我需要变身

{
  "DOCUMENT_HEADER_ID" : "29120",
  "invoice" : [ 
  {
    "DOCUMENT_HEADER_ID" : "29120",
    "Descrizione" : "GAS",
    "PrezzoTotale" : "8.51"
  }, {
    "DOCUMENT_HEADER_ID" : "29120",
    "Descrizione" : "IMPOSTE",
    "PrezzoTotale" : "7.25"
  },
  ...
  ]
}

使用此规范

[
  {
    "operation": "shift",
    "spec": {
      "@": "invoice"
    }
  }
]

我有这个输出:

{
  "invoice" : [ {
    "DOCUMENT_HEADER_ID" : "29120",
    "Descrizione" : "GAS",
    "PrezzoTotale" : "8.51"
  }, {
    "DOCUMENT_HEADER_ID" : "29120",
    "Descrizione" : "IMPOSTE",
    "PrezzoTotale" : "7.25"
  },
  ...
  ]
}

但我不知道如何从原始数组

的第一个元素中提取DOCUMENT_HEADER_ID的值

我找到了正确的规范

[
  {
    "operation": "shift",
    "spec": {
      "@": "invoice"
    }
  },
  {
    "operation": "shift",
    "spec": {
      "invoice": {
        "0": {
          "DOCUMENT_HEADER_ID": "DOCUMENT_HEADER_ID"
        },
        "@": "invoice"
      }
    }
  }
]

可以在一个班次内完成。

[
  {
    "operation": "shift",
    "spec": {
      "@": "invoice",
      "0": {
        "DOCUMENT_HEADER_ID": "DOCUMENT_HEADER_ID"
      }
    }
  }
]

如果必须检索单个元素,数据如:

"array_field": ["array_single_element"]

可以使用:

{
"operation": "modify-overwrite-beta",
"spec": {
  "array_field": "=concat(@(1,array_field))",
  "*": "=concat(@(1,&))"
}
}