Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ember.js/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
搜索JSON文件bash_Json_Bash - Fatal编程技术网

搜索JSON文件bash

搜索JSON文件bash,json,bash,Json,Bash,我有以下JSON文件,并希望提取其中的一部分: { "expand": "names,schema", "issues": [ { "expand": "operations,versionedRepresentations,editmeta,changelog,renderedFields", "fields": { "aggregateprogress": {

我有以下JSON文件,并希望提取其中的一部分:

  {
    "expand": "names,schema",
    "issues": [
        {
            "expand": "operations,versionedRepresentations,editmeta,changelog,renderedFields",
            "fields": {
                "aggregateprogress": {
                    "progress": 0,
                    "total": 0
                },
                "aggregatetimeestimate": null,
                "aggregatetimeoriginalestimate": null,
                "aggregatetimespent": null,
                "assignee": {
                    "active": true,
                    "avatarUrls": {
                        "16x16": "https://secure.gravatar.com/avatar/5d92f3ce51d4a090cdcb9b77ee890989?d=mm&s=16",
                        "24x24": "https://secure.gravatar.com/avatar/5d92f3ce51d4a090cdcb9b77ee890989?d=mm&s=24",
                        "32x32": "https://secure.gravatar.com/avatar/5d92f3ce51d4a090cdcb9b77ee890989?d=mm&s=32",
                        "48x48": "https://secure.gravatar.com/avatar/5d92f3ce51d4a090cdcb9b77ee890989?d=mm&s=48"
                    },
                    "displayName": "user",
                    "emailAddress": "user@company.com",
                    "key": "user",
                    "name": "user",
                    "self": "https://jira.corp.company.com/rest/api/2/user?username=dvucanovic",
                    "timeZone": "Europe/Belgrade"
                },
                "components": [],
                "created": "2018-03-06T21:24:41.000+0000",
                "creator": {
                    "active": true,
                    "avatarUrls": {
                        "16x16": "https://secure.gravatar.com/avatar/5d92f3ce51d4a090cdcb9b77ee890989?d=mm&s=16",
                        "24x24": "https://secure.gravatar.com/avatar/5d92f3ce51d4a090cdcb9b77ee890989?d=mm&s=24",
                        "32x32": "https://secure.gravatar.com/avatar/5d92f3ce51d4a090cdcb9b77ee890989?d=mm&s=32",
                        "48x48": "https://secure.gravatar.com/avatar/5d92f3ce51d4a090cdcb9b77ee890989?d=mm&s=48"
                    },
                    "displayName": "user",
                    "emailAddress": "user@company.com",
                    "key": "user",
                    "name": "user",
                    "self": "https://jira.corp.company.com/rest/api/2/user?username=dvucanovic",
                    "timeZone": "Europe/Belgrade"
                },
                "customfield_10000": null,
                "customfield_10001": null,
                "customfield_10002": null,
                "customfield_10004": "0|i00uta:",
                "customfield_10005": null,
                "customfield_10006": null,
                "customfield_10100": null,
                "customfield_10101": [],
                "customfield_10102": null,
                "customfield_10103": null,
                "customfield_10107": {
                    "id": "10400",
                    "self": "https://jira.corp.company.com/rest/api/2/customFieldOption/10400",
                    "value": "Hentsu Internal"
                },
                "customfield_10108": null,
                "customfield_10200": null,
                "customfield_10201": "2018-03-06",
                "customfield_10202": "2018-03-06",
                "customfield_10203": null,
                "customfield_10204": null,
                "customfield_10205": null,
                "customfield_10206": null,
                "customfield_10300": "com.atlassian.servicedesk.plugins.approvals.internal.customfield.ApprovalsCFValue@5e6792fb",
                "customfield_10301": null,
                "customfield_10302": null,
                "customfield_10600": null,
                "customfield_10700": null,
                "customfield_11000": null,
                "customfield_11001": null,
                "customfield_11002": null,
                "customfield_11003": null,
                "customfield_11004": null,
                "customfield_11005": null,
                "customfield_11006": null,
                "customfield_11007": null,
                "customfield_11008": null,
                "customfield_11009": null,
                "customfield_11010": null,
                "customfield_11011": null,
                "customfield_11012": null,
                "customfield_11013": null,
                "customfield_11014": null,
                "customfield_11015": null,
                "customfield_11016": null,
                "customfield_11017": null,
                "customfield_11018": null,
                "customfield_11019": null,
                "customfield_11100": null,
                "customfield_11101": null,
                "customfield_11102": null,
                "description": null,
                "duedate": null,
                "environment": null,
                "fixVersions": [],
                "issuelinks": [],
                "issuetype": {
                    "avatarId": 10318,
                    "description": "A task that needs to be done.",
                    "iconUrl": "https://jira.corp.company.com/secure/viewavatar?size=xsmall&avatarId=10318&avatarType=issuetype",
                    "id": "10100",
                    "name": "Task",
                    "self": "https://jira.corp.company.com/rest/api/2/issuetype/10100",
                    "subtask": false
                },
                "labels": [],
                "lastViewed": "2018-03-06T21:31:34.315+0000",
                "priority": {
                    "iconUrl": "https://jira.corp.company.com/images/icons/priorities/medium.svg",
                    "id": "3",
                    "name": "Medium",
                    "self": "https://jira.corp.company.com/rest/api/2/priority/3"
                },
                "progress": {
                    "progress": 0,
                    "total": 0
                },
                "project": {
                    "avatarUrls": {
                        "16x16": "https://jira.corp.company.com/secure/projectavatar?size=xsmall&pid=10001&avatarId=10201",
                        "24x24": "https://jira.corp.company.com/secure/projectavatar?size=small&pid=10001&avatarId=10201",
                        "32x32": "https://jira.corp.company.com/secure/projectavatar?size=medium&pid=10001&avatarId=10201",
                        "48x48": "https://jira.corp.company.com/secure/projectavatar?pid=10001&avatarId=10201"
                    },
                    "id": "10001",
                    "key": "TECH",
                    "name": "Technology",
                    "self": "https://jira.corp.company.com/rest/api/2/project/10001"
                },
                "reporter": {
                    "active": true,
                    "avatarUrls": {
                        "16x16": "https://secure.gravatar.com/avatar/5d92f3ce51d4a090cdcb9b77ee890989?d=mm&s=16",
                        "24x24": "https://secure.gravatar.com/avatar/5d92f3ce51d4a090cdcb9b77ee890989?d=mm&s=24",
                        "32x32": "https://secure.gravatar.com/avatar/5d92f3ce51d4a090cdcb9b77ee890989?d=mm&s=32",
                        "48x48": "https://secure.gravatar.com/avatar/5d92f3ce51d4a090cdcb9b77ee890989?d=mm&s=48"
                    },
                    "displayName": "user",
                    "emailAddress": "user@company.com",
                    "key": "user",
                    "name": "user",
                    "self": "https://jira.corp.company.com/rest/api/2/user?username=dvucanovic",
                    "timeZone": "Europe/Belgrade"
                },
                "resolution": null,
                "resolutiondate": null,
                "status": {
                    "description": "",
                    "iconUrl": "https://jira.corp.company.com/",
                    "id": "10000",
                    "name": "Backlog",
                    "self": "https://jira.corp.company.com/rest/api/2/status/10000",
                    "statusCategory": {
                        "colorName": "blue-gray",
                        "id": 2,
                        "key": "new",
                        "name": "To Do",
                        "self": "https://jira.corp.company.com/rest/api/2/statuscategory/2"
                    }
                },
                "subtasks": [
                    {
                        "fields": {
                            "issuetype": {
                                "avatarId": 10316,
                                "description": "The sub-task of the issue",
                                "iconUrl": "https://jira.corp.company.com/secure/viewavatar?size=xsmall&avatarId=10316&avatarType=issuetype",
                                "id": "10101",
                                "name": "Sub-task",
                                "self": "https://jira.corp.company.com/rest/api/2/issuetype/10101",
                                "subtask": true
                            },
                            "priority": {
                                "iconUrl": "https://jira.corp.company.com/images/icons/priorities/medium.svg",
                                "id": "3",
                                "name": "Medium",
                                "self": "https://jira.corp.company.com/rest/api/2/priority/3"
                            },
                            "status": {
                                "description": "",
                                "iconUrl": "https://jira.corp.company.com/",
                                "id": "10000",
                                "name": "Backlog",
                                "self": "https://jira.corp.company.com/rest/api/2/status/10000",
                                "statusCategory": {
                                    "colorName": "blue-gray",
                                    "id": 2,
                                    "key": "new",
                                    "name": "To Do",
                                    "self": "https://jira.corp.company.com/rest/api/2/statuscategory/2"
                                }
                            },
                            "summary": "Disable user account in Local AD"
                        },
                        "id": "16916",
                        "key": "TECH-728",
                        "self": "https://jira.corp.company.com/rest/api/2/issue/16916"
                    }
                ],
                "summary": "disable user mm",
                "timeestimate": null,
                "timeoriginalestimate": null,
                "timespent": null,
                "updated": "2018-03-06T21:27:22.000+0000",
                "versions": [],
                "votes": {
                    "hasVoted": false,
                    "self": "https://jira.corp.company.com/rest/api/2/issue/TECH-726/votes",
                    "votes": 0
                },
                "watches": {
                    "isWatching": true,
                    "self": "https://jira.corp.company.com/rest/api/2/issue/TECH-726/watchers",
                    "watchCount": 1
                },
                "workratio": -1
            },
            "id": "16914",
            "key": "TECH-726",
            "self": "https://jira.corp.company.com/rest/api/2/issue/16914"
        }
    ],
    "maxResults": 50,
    "startAt": 0,
    "total": 1
}
如何仅提取子任务部分中的部分

(子任务:true)

试用:

jq -r '.issues[] | .fields.issuetype.subtask' 1.json # and
jq -r '.subtasks[] |.fields.issuetype.subtask' 1.json
但总是弄虚作假

jq -r '.subtasks[] | .fields.issuetype.subtask' 1.json
jq: error (at 1.json:231): Cannot iterate over null (null)

jq
解决方案:

jq '.issues[].fields.subtasks[].fields | .issuetype.subtask, .summary' 1.json
输出:

true
"Disable user account in Local AD"

关于在bash中迭代输出的最佳实践机制(这里假设
子任务
字段永远不包含文本选项卡,
摘要
永远不包含文本换行符):

而IFS=$'\t'read-r子任务摘要;做
echo“获得子任务$subtask和摘要$summary”

已完成<您是否可以包括您的预期输出?要获得子任务的值true和摘要值:“禁用本地广告中的用户帐户”尝试将上述内容放入变量中:
cat 1.json | jq.issues[]fields.subtask[].fields |.issuetype.subtask
但获取:.issuetype.subtask:如果我在“cat 1.json | jq.issues[].fields.subtask[].fields |.issuetype.subtask”中放置自定义_字段,则找不到命令;然后不出错,但我在上面代码中得到的变量输出的安装,当放回勾号时,然后得到errorworks:for custom_字段(jq'.issues[].fields.subtask[].fields |.issuetype.subtask'1.json);do@Milister,不要那样做。请参阅,以及——关于应该使用的最佳实践——(要清楚,这个答案很好;在$(…)中使用
for字段来迭代其结果是不正确的)。
while IFS=$'\t' read -r subtask summary; do
  echo "Got subtask $subtask and summary $summary"
done < <(jq -r '.issues[].fields.subtasks[].fields
                | [.issuetype.subtask, .summary] | @tsv')
while IFS= read -r -d '' subtask && IFS= read -r -d '' summary; do
  printf 'Got subtask %q and summary %q\n' "$subtask" "$summary"
done < <(jq -j '.issues[].fields.subtasks[].fields
                | (.issuetype.subtask, "\u0000", .summary, "\u0000")')