我想在一个数组中找到一些键值,并将它们与其他数组中的相应值进行匹配。作为参考,我正在使用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中很容易。