我似乎无法弄清楚 JOLT 到了令人沮丧的地步..
我可以毫无问题地将所有值放入单个嵌套数组中,但是我无法将值添加到输出的根。
数据:
[ {
"Q" : "10",
"W" : "0.5",
"O" : "Oregon",
"Status" : "Valid",
"Type" : "SSD",
"Number" : "Samsung1234",
"Total" : "50",
"Category" : "Drive"
},
{
"Q" : "15",
"W" : "0.5",
"O" : "Seattle",
"Status" : "Valid",
"Type" : "SSD",
"Number" : "PNY1234",
"Total" : "100",
"Category" : "Drive"
}
...
]
当前规格:
[{
"operation": "shift",
"spec": {
"*": "data.drives"
}
}]
这给了我以下结构:
{
"data" : {
"drives" : [ {
"Q" : "10",
"W" : "0.5",
"O" : "Oregon",
"Status" : "Valid",
"Type" : "SSD",
"Number" : "Samsung1234",
"Total" : "50",
"Category" : "Drive"
},
{
"Q" : "15",
"W" : "0.5",
"O" : "Seattle",
"Status" : "Valid",
"Type" : "SSD",
"Number" : "Samsung1234",
"Total" : "100",
"Category" : "Drive"
}
}]
...
}
我需要的是:
{
"data" : {
"Number" : "Samsung1234",
"Category" : "Drive",
"Type" : "SSD",
"drives" : [ {
"Q" : "10",
"W" : "0.5",
"O" : "Oregon",
"Status" : "Valid",
"Total" : "50"
},
{
"Q" : "15",
"W" : "0.5",
"O" : "Seattle",
"Status" : "Valid",
"Total" : "100"
}
}]
...
}
非常感谢任何帮助。颠簸对我来说仍然是一个谜,我只是无法理解它..
如果目标是仅获取第一个
Number
、Category
和 Type
值,则可以使用以下转换:
[
{
"operation": "shift",
"spec": {
"*": {
"Number|Category|Type": "data.&",
"*": "data.drives[&1].&" // all other attributes
}
}
},
{
"operation": "cardinality",
"spec": {
"*": {
"drives": "MANY", // keep this array as it is
"*": "ONE" // bring only the first components
// of the arrays respectively
}
}
}
]