假设json定义如下:
{
"name": "To",
"mapfld": {
"AA": "aa",
"BB": "bb"
}
}
输出key
$ cat t.json | jq -r '.mapfld | keys[]'
AA
BB
格式化key
$ cat t.json | jq -r '.mapfld | keys[] as $k | "\($k)"'
AA
BB
$ cat t.json | jq -r '.mapfld | keys[] as $k | "aa\($k)bb"'
aaAAbb
aaBBbb
输出value
$ cat t.json | jq -r '.mapfld | keys[] as $k | "\(.[$k])"'
aa
bb
格式化value
$ cat t.json | jq -r '.mapfld | keys[] as $k | "--\(.[$k])--"'
--aa--
--bb--
输出key和value
$ cat t.json | jq -r '.mapfld | keys[] as $k | "\($k)=\(.[$k])"'
AA=aa
BB=bb
网友评论