[英]Assigning jq output to bash array when json value contains spaces
[英]sort json array by value jq bash
我想下面的排序基于阵列上groupId
,使得具有更小的键groupId
来首次在阵列。
[
{
"groupId": 11,
"lowerThreshold": 33,
"target": {
"alarm_id": 22
},
"thresholdPeriod": 3,
"upperThreshold": 44
},
{
"groupId": 31,
"lowerThreshold": 33,
"target": {
"alarm_id": 122
},
"thresholdPeriod": 3,
"upperThreshold": 44
},
{
"groupId": "0",
"target": {
"alarm_id": "69"
},
"upperThreshold": "20",
"lowerThreshold": "10",
"thresholdPeriod": "5"
}
]
期望是
[
{
"groupId": "0",
"target": {
"alarm_id": "69"
},
"upperThreshold": "20",
"lowerThreshold": "10",
"thresholdPeriod": "5"
},
{
"groupId": 11,
"lowerThreshold": 33,
"target": {
"alarm_id": 22
},
"thresholdPeriod": 3,
"upperThreshold": 44
},
{
"groupId": 31,
"lowerThreshold": 33,
"target": {
"alarm_id": 122
},
"thresholdPeriod": 3,
"upperThreshold": 44
}
]
您可以使用sort_by
如下:
jq 'sort_by(.groupId)'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.