【发布时间】:2018-11-12 15:12:01
【问题描述】:
我有一个 jenkins JSON API,它给我一个存储在变量 data 中的输出
{"credentials":{"xxxxxxxxxxxxxx111":{},"xxxxxxxxxxxx2222":{}},"description":"All credentials that are not bound to a specific domain.","displayName":"Global credentials","fullDisplayName":"Credentials » Global credentials","fullName":"credential-store/_","global":true,"urlName":"_"}
我只想要凭证字段 xxxxxxxxxxxxxx111 和 xxxxxxxxxxxx2222 的值
到目前为止我尝试过的事情是
echo $data | grep "credentials"
echo $data | jq -e '.credentials[]|{}' -c
这不起作用 有人可以建议一些可行的方法吗?
【问题讨论】:
-
在您的示例中,
credentials对象内的元素是空对象。你在看什么价值观?请使用预期的输出更新您的问题。 -
我在这里寻找 xxxxxxxxxxxxxx111 和 xxxxxxxxxxxx2222 的值,它们是 {"xxxxxxxxxxxxxx111":{},"xxxxxxxxxxxx2222":{}} 第一组花括号中的值