Json
如何讓 jq 生成 json 字典的值數組?
我有一
json
本字典$ cat foo.json { "black": "#073642", "red": "#DC322F", "green": "#859900", "yellow": "#CF9A6B", "blue": "#268BD2", "purple": "#D33682", "cyan": "#2AA198", "white": "#EEE8D5", "brightBlack": "#657B83", "brightRed": "#D87979", "brightGreen": "#88CF76", "brightYellow": "#657B83", "brightBlue": "#2699FF", "brightPurple": "#D33682", "brightCyan": "#43B8C3", "brightWhite": "#FDF6E3", "foreground": "#839496", "background": "#002B36", "cursorColor": "#839496" }
我想用它
jq
來列印出這本字典中的所有值。所以,輸出應該是:$ jq 'magic' foo.json #073642 #DC322F #859900 #CF9A6B #268BD2 #D33682 #2AA198 #EEE8D5 #657B83 #D87979 #88CF76 #657B83 #2699FF #D33682 #43B8C3 #FDF6E3 #839496 #002B36 #839496
'magic'
我在找什麼?
您也可以在對像上使用它,它將返回對象的所有值。
要獲得準確的結果,您還需要
jq -r
/--raw-output
省略 JSON 字元串引號:jq -r '.[]' foo.json