我有如下所示的 json:
% cat example.json
{
"values" : [
{
"title": "B",
"url": "https://B"
},
{
"title": "A",
"url": "https://A"
}
]
}
Run Code Online (Sandbox Code Playgroud)
我想根据标题对值进行排序。即预期输出
{
"title": "A",
"url": "https://A"
}
{
"title": "B",
"url": "https://B"
}
Run Code Online (Sandbox Code Playgroud)
尝试了一下打击。不起作用:
% jq '.values[] | sort' example.json
jq: error (at example.json:12): object ({"title":"B...) cannot be sorted, as it is not an array
% jq '.values[] | sort_by(.title)' example.json
jq: error (at example.json:12): Cannot index string with string "title"
Run Code Online (Sandbox Code Playgroud)