如何从此JSON文件中提取单词

时间:2019-01-11 06:58:51

标签: json jq

我想从此JSON文件中获取type个结果。我该怎么办?

{
    "inputs": [{
        "title": "vault_beats",
        "global": true,
        "name": "Beats",
        "content_pack": null,
        "created_at": "2019-01-11T05:31:49.720Z",
        "type": "org.graylog.plugins.beats.Beats2Input",
        "creator_user_id": "admin",
        "attributes": {
            "recv_buffer_size": 1048576,
            "tcp_keepalive": false,
            "number_worker_threads": 1,
            "tls_client_auth_cert_file": "",
            "beats_prefix": false,
            "bind_address": "0.0.0.0",
            "tls_cert_file": "",
            "port": 5044,
            "tls_key_file": "admin",
            "tls_enable": false,
            "tls_key_password": "admin",
            "tls_client_auth": "disabled",
            "override_source": null
        },
        "static_fields": {},
        "node": null,
        "id": "5c382a45590801001d742017"
    }, {
        "title": "vault_beatsl",
        "global": true,
        "name": "GELF TCP",
        "content_pack": null,
        "created_at": "2019-01-11T05:32:05.869Z",
        "type": "org.graylog2.inputs.gelf.tcp.GELFTCPInput",
        "creator_user_id": "admin",
        "attributes": {
            "recv_buffer_size": 1048576,
            "tcp_keepalive": false,
            "use_null_delimiter": true,
            "number_worker_threads": 1,
            "tls_client_auth_cert_file": "",
            "bind_address": "0.0.0.0",
            "tls_cert_file": "",
            "decompress_size_limit": 8388608,
            "port": 12201,
            "tls_key_file": "admin",
            "tls_enable": false,
            "tls_key_password": "admin",
            "max_message_size": 2097152,
            "tls_client_auth": "disabled",
            "override_source": null
        },
        "static_fields": {},
        "node": null,
        "id": "5c382a55590801001d74202b"
    }],
    "total": 2
}

示例输出:-

"type":"org.graylog.plugins.beats.Beats2Input"
"type":"org.graylog2.inputs.gelf.tcp.GELFTCPInput"

1 个答案:

答案 0 :(得分:1)

这些要求有点模糊,但是当与-r命令行选项一起使用时,以下内容会产生所需的输出并具有简单性的优点,但是您可能需要对其进行调整以满足您的确切要求:

.. | objects | select(.type) | "\"type\":\"\(.type)\""