{"expand":"renderedFields,names,schema,operations,editmeta,changelog,versionedRepresentations","id":"15114","self":"https://brg-jira-tst.state.mi.us/rest/api/2/issue/15114","key":"BRGTEST-11","fields":{"issuetype":{"self":"https://brg-jira-tst.state.mi.us/rest/api/2/issuetype/10200","id":"10200","description":"A task that needs to be done associated with Bridges project","iconUrl":"https://brg-jira-tst.state.mi.us/secure/viewavatar?size=xsmall&avatarId=10318&avatarType=issuetype","name":"Task","subtask":false,"avatarId":10318},"customfield_11500":"QAT"}}
Run Code Online (Sandbox Code Playgroud)
以上是我存储在 a.json 中的 json 响应
我想使用 shell 脚本从这个 a.json 响应中提取 customfield_11500 的值。怎么做
在这种情况下,我的 shell 命令的输出必须给出结果为“QAT”
不喜欢滚动的格式化 JSON:
{
"expand": "renderedFields,names,schema,operations,editmeta,changelog,versionedRepresentations",
"id": "15114",
"self": "https://brg-jira-tst.state.mi.us/rest/api/2/issue/15114",
"key": "BRGTEST-11",
"fields": {
"issuetype": {
"self": "https://brg-jira-tst.state.mi.us/rest/api/2/issuetype/10200",
"id": "10200",
"description": "A task that needs to be done associated with Bridges project",
"iconUrl": "https://brg-jira-tst.state.mi.us/secure/viewavatar?size=xsmall&avatarId=10318&avatarType=issuetype",
"name": "Task",
"subtask": false,
"avatarId": 10318
},
"customfield_11500": "QAT"
}
}
Run Code Online (Sandbox Code Playgroud)
基于这篇文章 并使用格式化的 json 文件
grep -oP '(?<="customfield_11500": ")[^"]*' a.json
Run Code Online (Sandbox Code Playgroud)
使用最新版本的ksh93shell(v-或更高版本):
read -m json j < file.json &&
print -r -- "${j.fields.customfield_11500}"
Run Code Online (Sandbox Code Playgroud)
或者使用广泛可用的(尽管默认情况下通常不安装)jqjson 处理器工具:
jq -r '.fields.customfield_11500' file.json
Run Code Online (Sandbox Code Playgroud)