我想在一個數組中找到一些鍵值,並將它們與其他數組中的相應值進行匹配。作爲參考,我正在使用jq-1.5jq 1.5:將一個數組中的鍵與它們在不同數組中的值結合起來
我從quandl api獲取了一些數據,我在這裏提取一些股票數據。例如,下面的內容會拉下一些json數據。
的數據如下,雖然我已經刪除一些冗餘數據的;
{
"datatable": {
"data": [
["2012-05-18", 38.2318, 45.0, 38.0],
["2012-05-21", 34.03, 36.66, 33.0],
["2012-05-22", 31.0, 33.59, 30.94],
["2017-06-22", 153.4, 154.55, 152.91],
["2017-06-23", 155.07, 155.2, 152.65]
],
"columns": [{
"name": "date",
"type": "Date"
}, {
"name": "close",
"type": "BigDecimal(34,12)"
}, {
"name": "high",
"type": "BigDecimal(34,12)"
}, {
"name": "low",
"type": "BigDecimal(34,12)"
}]
},
"meta": {
"next_cursor_id": null
}
}
我期待與.datatable.data的「價值觀」匹配來自.datatable.columns [$索引1]。名稱的「鑰匙」 [1]等每個迭代索引值。我期待得到如下的輸出;
[
{
"date": "2012-05-18",
"close": 38.2318,
"high": 45.0,
"low": 38.0
},
{
"date": "2012-05-21",
"close": 34.03,
"high": 36.66,
"low": 33.0
},
{
"date": "2012-05-22",
"close": 31.0,
"high": 33.59,
"low": 30.94
},
{
"date": "2017-06-22",
"close": 153.4,
"high": 154.55,
"low": 152.91
},
{
"date": "2017-06-23",
"close": 155.07,
"high": 155.2,
"low": 152.65
}
]
到目前爲止,我打得四處計數指數的想法,但我大部分的解決方案,到目前爲止已經相當冗長,我發現自己走出JQ對SED/AWK等對於我想象的東西在jq中很容易。