jq + 如何仅打印属性下键的值

jq + 如何仅打印属性下键的值

我们有以下 json 文件

 more t.json
{
  "href" : "htr",
  "items" : [
    {
      "href" : "lpo",
      "tag" : "version1533203561827110",
      "type" : "kafka-log4j",
      "version" : 6,
      "Config" : {
        "cluster_name" : "hdp",
        "stack_id" : "HDP-2.6"
      },
      "properties" : {
        "content" : "Licensed to the Apache Software Foundation",
        "controller_log_maxbackupindex" : "20",
        "controller_log_maxfilesize" : "256",
        "ey=log4j.rootLogger" : "DEBUG",
        "ey=properties.content" : "DEBUG",
        "kafka_log_maxbackupindex" : "20",
        "kafka_log_maxfilesize" : "256"
      }
    }
  ]
}

我们只想打印内容的值

jq '.items[].properties | to_entries[] |  " \(.value)"' t.json
" Licensed to the Apache Software Foundation"
" 20"
" 256"
" DEBUG"
" DEBUG"
" 20"
" 256"

但它打印所有其他值

我哪里错了,我应该纠正什么?

预期产出

" Licensed to the Apache Software Foundation"

答案1

尝试这个,

jq '.items[].properties.content' t.json

-r如果您想去掉双引号,请添加

相关内容