Json文件获取属性



json输出是这样的。可多可少:

{
"values": [
{
"id": "9207968154959e84a61207773ba595bab4e09a74",
"displayId": "92079681549",
"author": {
"name": "ADBE08",
"emailAddress": "adam.svensson@hotmail.com",
"id": 30405,
"displayName": "Adam svensson",
"active": true,
"slug": "adbe08",
"type": "NORMAL"
},
"authorTimestamp": 1650961815000,
"committer": {
"name": "ADBE08",
"emailAddress": "adam.svensson@hotmail.com",
"id": 30405,
"displayName": "Adam svensson",
"active": true,
"slug": "adbe08",
"type": "NORMAL"
},
"committerTimestamp": 1650961815000,
"message": "fixes sonar issues",
"parents": [
{
"id": "fe037562528e899c2e76c42cd261d227f0884f81",
"displayId": "fe037562528"
}
]
},

{
"id": "9b722800273e421ec4a5add0a4cc624ca04347f0",
"displayId": "9b722800273",
"author": {
"name": "ADBE08",
"emailAddress": "adam.svensson@hotmail.com",
"id": 30405,
"displayName": "Adam svensson",
"active": true,
"slug": "adbe08",
"type": "NORMAL"
},
"authorTimestamp": 1650622775000,
"committer": {
"name": "ADBE08",
"emailAddress": "adam.svensson@hotmail.com",
"id": 30405,
"displayName": "Adam svensson",
"active": true,
"slug": "adbe08",
"type": "NORMAL"
},
"committerTimestamp": 1650622775000,
"message": "removes profiles for testing purpose",
"parents": [
{
"id": "1f1adad1754b064aba630f7df3a8f196dc4478fe",
"displayId": "1f1adad1754"
}
]
},
{
"id": "1f1adad1754b064aba630f7df3a8f196dc4478fe",
"displayId": "1f1adad1754",
"author": {
"name": "ADBE08",
"emailAddress": "adam.svensson@hotmail.com",
"id": 30405,
"displayName": "Adam svensson",
"active": true,
"slug": "adbe08",
"type": "NORMAL"
},
"authorTimestamp": 1650620887000,
"committer": {
"name": "ADBE08",
"emailAddress": "adam.svensson@hotmail.com",
"id": 30405,
"displayName": "Adam svensson",
"active": true,
"slug": "adbe08",
"type": "NORMAL"
},
"committerTimestamp": 1650620887000,
"message": "Merge remote-tracking branch 'origin/feat-KOKO-8243-csca-dd-priv-some-create-purchase-for-test' into feat-debug-menu",
"parents": [
{
"id": "01332cb1374c34aeb2a91b69029f4f4072ea147d",
"displayId": "01332cb1374"
},
{
"id": "8e36ec4b3aacda03b5e52bc8df0c43d44f49c72e",
"displayId": "8e36ec4b3aa"
}
],
"properties": {
"jira-key": [
"KOKO-8243"
]
}
},
{
"id": "8e36ec4b3aacda03b5e52bc8df0c43d44f49c72e",
"displayId": "8e36ec4b3aa",
"author": {
"name": "niol05",
"emailAddress": "anna.olsson@hotmail.com",
"id": 27253,
"displayName": "anna Olsson",
"active": true,
"slug": "niol05",
"type": "NORMAL"
},
"authorTimestamp": 1644848083000,
"committer": {
"name": "niol05",
"emailAddress": "anna.olsson@hotmail.com",
"id": 27253,
"displayName": "anna Olsson",
"active": true,
"slug": "niol05",
"type": "NORMAL"
},
"committerTimestamp": 1644848083000,
"message": "Merge branch 'dev' into feat-KOKO-8243-csca-dd-priv-some-create-purchase-for-test",
"parents": [
{
"id": "633747c469cf488a92f3a29034a47c1f42c1fd81",
"displayId": "633747c469c"
},
{
"id": "1466e5fbfee12dce35fa21c35c157e9ce934ff9e",
"displayId": "1466e5fbfee"
}
],
"properties": {
"jira-key": [
"KOKO-8243"
]
}
},
{
"id": "4b5b85beabb8a7779ab13a5e5de3108103e1cc8b",
"displayId": "4b5b85beabb",
"author": {
"name": "niol05",
"emailAddress": "anna.olsson@hotmail.com",
"id": 27253,
"displayName": "anna Olsson",
"active": true,
"slug": "niol05",
"type": "NORMAL"
},
"authorTimestamp": 1623928598000,
"committer": {
"name": "niol05",
"emailAddress": "anna.olsson@hotmail.com",
"id": 27253,
"displayName": "anna Olsson",
"active": true,
"slug": "niol05",
"type": "NORMAL"
},
"committerTimestamp": 1623928598000,
"message": "Added support for creating test purchase",
"parents": [
{
"id": "7f7da00e46f415fd7f593f0951d04910149ff786",
"displayId": "7f7da00e46f"
}
]
}
],
"size": 5,
"isLastPage": false,
"start": 0,
"limit": 25,
"nextPageStart": 25
}

我想在"jira-key"中显示所有信息。外汇"properties"{"jira-key"["可可- 13230"]}将会连续显示这个提交。下一个jira-key提交到新行。

外汇:

  • 可可- 13230
  • 可可- 12443
  • 可可- 3342
  • 可可- 32142
  • 可可- 334212

我该怎么做呢?我使用bash

您可以使用jq工具查找所有values.properties.jira-key数据。您的示例提供给以下命令:

jq '.values[].properties?."jira-key"[]?' < example

会产生:

"KOKO-8243"
"KOKO-8243"

如果你的json像上面一样打印得很好,你也可以尝试使用awk:

编写一些hack代码:
awk '/]/ { ok=0 } // { if (ok==1) { print $1 } } /"jira-key":/ { ok=1 }' < example
对于您的示例数据,它应该显示相同的输出。

最新更新