【发布时间】:2022-10-24 22:28:40
【问题描述】:
我有一个名为 param.json 的 json 文件,如下所示:
[
{
"Value": "anshuman.ceg+Dev@gmail.com",
"Key": "AccountEmail"
},
{
"Value": "DevABC",
"Key": "AccountName"
},
{
"Value": "Security (ou-nzx5-8ajd1561)",
"Key": "ManagedOrganizationalUnit"
},
{
"Value": "anshuman.ceg+Dev@gmail.com",
"Key": "SSOUserEmail"
},
{
"Value": "John",
"Key": "SSOUserFirstName"
},
{
"Value": "Smith",
"Key": "SSOUserLastName"
}
]
我只想获得价值开发ABC这样我就可以在阅读 -r 行时使用。我只需要 DevABC
我正在使用 jq 如下似乎不起作用
jq -r .[1].Value param.json
【问题讨论】:
-
您需要在过滤器周围加上引号:
jq -r '.[1].Value' param.json。您可能也有兴趣使用jq -r 'from_entries.AccountName' param.json。 -
@Anshuman_Mishra - 请明确说明“DevABC”与其他值的区别。是 .Key 的值吗?还是它在数组中的位置?
标签: jq