我使用下面的长命令来获得JSON值7.3.9-win-x64.msi,我将其包含在下面.

$ cat json.txt  | jq -r '.[] | .[] | .[] | .[].management | .[0].microsoft | .shell.associated.scripting.component.windows.powershell'

对于JSON代码,它是:

{
  "PowerShell": {
    "is a task": {
      "automation": [
        {
          "and": "configuration",
          "management": [
            {
              "program": "from",
              "microsoft": {
                "consisting of": "a command-line",
                "shell": {
                  "and": "the",
                  "associated": {
                    "scripting": {
                      "language.": "initially a windows",
                      "component": {
                        "only": "known as",
                        "windows": {
                          "powershell": "7.3.9-win-x64.msi",
                          "it was made": "open-source"
                        }
                      }
                    }
                  }
                }
              }
            }
          ]
        },
        {
          "the former": "is built on the .NET Framework",
          "the latter on": ".NET (previously .NET Core)."
        }
      ]
    }
  }
}

当我试图应用从互联网上的几篇文章中获得的几种方法来以更短的方式获得相同的价值时,我失败了.那么,有没有更短的命令来做到这一点呢?

推荐答案

如果必须按照您的try 指定完整路径,您可以通过跳过显式管道来稍微缩短它:

.[][][][].management[0].microsoft.shell.associated.scripting.component.windows.powershell

Json相关问答推荐

Elasticsearch Go客户端错误:无效的SON格式:在中间件中索引文档时出错

NIFI-我需要数组的信息,但只需要第一个信息

有没有办法让serde_json正确/不正确地处理NaN、inf和-inf(IEEE 754特殊标准)?

解析Ansible AWS ec2_security_group中的json以提取安全组ID

Android 如何判断小时时间是否在两个时间之间?

如何将具有相同 struct 的多个JSON文件中的对象数组合并成一个数组?

jq - 仅在键值对存在的地方打印值

从 oracle 数据库中的 json blob 打印值

try 使用 JQ 转换 JSON 中过于复杂的对象数组

用于遮蔽卡的 Jolt 规格

如何为名称/值 struct 创建 JSON 模式?

使用 Spring 和 JsonTypeInfo 注释将 JSON 反序列化为多态对象模型

Rails 中奇怪的 JSON Javascript 问题

消息通知产生此内容无法显示

将 JSON 对象推送到 localStorage 中的数组

使用 ajax 将 JSON 发送到 PHP

[__NSCFNumber 长度]:发送到实例 UITableView 的无法识别的 Select 器

通过url获取json数据并在python中使用(simplejson)

Java HashMap 与 JSONObject

为什么 jqXHR.responseText 返回字符串而不是 JSON 对象?