I have the following JSON file with example values:

{
    "files": [{
        "fileName": "FOO",
        "md5": "blablabla"
    }, {
        "fileName": "BAR",
        "md5": "alaldlafj"
    }]
}

Now what I want is to return the md5 value where for example the fileName is "FOO". For this I have the following statement in jq:

cat <file>.json | jq '.[] | select(.fileName=="FOO")' 

然而,回应是:jq: error (at <stdin>:11): Cannot index array with string "fileName"

在密钥文件名等于某个参数的情况下,返回MD5值的正确方式是什么?

推荐答案

Found the answer:

cat <file>.json | jq -r '.files[] | select(.fileName=="FOO") | .md5'

Json相关问答推荐

为什么terraform不缩小这个策略JSON?'

从Json响应中为需要每个值的Post请求提取多个值

使用WSO2 JsonTransform Mediator对空值执行JsonExceptionUndeletedOperationException

PowerShell脚本未按预期生成预期的JSON输出

褐煤面积图中的分选问题

json 字符串到 Postgres 14 中的表视图

无法使用 vue.js 访问 JSON 数组的项目

jq可以在两个JSON对象列表中依次添加对象吗?

我无法将来自 API 的数据显示到 FlatList 中,但我在 console.log 中看到了它.问题是什么?

如何删除 django jsonfield 中的特定项目

如何使用 CORS 实现 JavaScript Google Places API 请求

如何一次加载无限滚动中的所有条目以解析python中的HTML

如何从 mysql 数据库构建 JSON 数组

Jackson 中的 readValue 和 readTree:何时使用哪个?

alert Json 对象

Spring restTemplate 获取原始 json 字符串

MySQL Select JSON 字段属性具有值的位置

字符串格式 JSON 字符串给出 KeyError

将 JsonArray 添加到 JsonObject

Laravel 5 控制器将 JSON 整数作为字符串发送