Building json path from JQ using some keywordSafely turning a JSON string into an objectHow do I format a Microsoft JSON date?Can comments be used in JSON?How can I pretty-print JSON in a shell script?What is the correct JSON content type?Why does Google prepend while(1); to their JSON responses?Why can't Python parse this JSON data?How can I pretty-print JSON using JavaScript?Parse JSON in JavaScript?How do I POST JSON data with Curl from a terminal/commandline to Test Spring REST?

Why does the Pilatus PC-24 have such a large "Wing Support"?

Rank-one positive decomposition for a entry-wise positive positive definite matrix

What does a textbook look like while you are writing it?

Mac disaster! No longer boots - can’t finish my uni stuff

If I travelled back in time to invest in X company to make a fortune, roughly what is the probability that it would fail?

Can I bring this power bank on board the aircraft?

Is "weekend warrior" derogatory?

How dangerous are my worn rims?

How to say "respectively" in German when listing (enumerating) things

Does it require less energy to reach the Sun from Pluto's orbit than from Earth's orbit?

Parent asking for money after I moved out

Would a horse be sufficient buffer to prevent injury when falling from a great height?

Is the "spacetime" the same thing as the mathematical 4th dimension?

IEEE 754 square root with Newton-Raphson

Search for something difficult to count/estimate

Does Bank Manager's discretion still exist in Mortgage Lending

Disable all sound permanently

Job interview by video at home and privacy concerns

What did the Federation give the Prophets in exchange for access to the wormhole in DS9?

How important is knowledge of trig identities for use in Calculus

GPLv3 forces us to make code available, but to who?

Could Boris Johnson face criminal charges for illegally proroguing Parliament?

What are one's options when facing religious discrimination at the airport?

Is "Ram married his daughter" ambiguous?



Building json path from JQ using some keyword


Safely turning a JSON string into an objectHow do I format a Microsoft JSON date?Can comments be used in JSON?How can I pretty-print JSON in a shell script?What is the correct JSON content type?Why does Google prepend while(1); to their JSON responses?Why can't Python parse this JSON data?How can I pretty-print JSON using JavaScript?Parse JSON in JavaScript?How do I POST JSON data with Curl from a terminal/commandline to Test Spring REST?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;









0















I have a deep json. Sometimes, I need to look for the json path for a key containing certain word.




"apiVersion": "v1",
"kind": "Pod",
"metadata":
"creationTimestamp": "2019-03-28T21:09:42Z",
"labels":
"bu": "finance",
"env": "prod"
,
"name": "auth",
"namespace": "default",
"resourceVersion": "2786",
"selfLink": "/api/v1/namespaces/default/pods/auth",
"uid": "ce73565a-519d-11e9-bcb7-0242ac110009"
,
"spec":
"containers": [

"command": [
"sleep",
"4800"
],
"image": "busybox",
"imagePullPolicy": "Always",
"name": "busybox",
"resources": ,
"terminationMessagePath": "/dev/termination-log",
"terminationMessagePolicy": "File",
"volumeMounts": [

"mountPath": "/var/run/secrets/kubernetes.io/serviceaccount",
"name": "default-token-dbpcm",
"readOnly": true

]

],
"dnsPolicy": "ClusterFirst",
"nodeName": "node01",
"priority": 0,
"restartPolicy": "Always",
"schedulerName": "default-scheduler",
"securityContext": ,
"serviceAccount": "default",
"serviceAccountName": "default",
"terminationGracePeriodSeconds": 30,
"tolerations": [

"effect": "NoExecute",
"key": "node.kubernetes.io/not-ready",
"operator": "Exists",
"tolerationSeconds": 300
,

"effect": "NoExecute",
"key": "node.kubernetes.io/unreachable",
"operator": "Exists",
"tolerationSeconds": 300

],
"volumes": [

"name": "default-token-dbpcm",
"secret":
"defaultMode": 420,
"secretName": "default-token-dbpcm"


]
,
"status":
"conditions": [

"lastProbeTime": null,
"lastTransitionTime": "2019-03-28T21:09:42Z",
"status": "True",
"type": "Initialized"
,

"lastProbeTime": null,
"lastTransitionTime": "2019-03-28T21:09:50Z",
"status": "True",
"type": "Ready"
,

"lastProbeTime": null,
"lastTransitionTime": null,
"status": "True",
"type": "ContainersReady"
,

"lastProbeTime": null,
"lastTransitionTime": "2019-03-28T21:09:42Z",
"status": "True",
"type": "PodScheduled"

],
"containerStatuses": [

"containerID": "docker://b5be8275555ad70939401d658bb4e504b52215b70618ad43c2d0d02c35e1ae27",
"image": "busybox:latest",
"imageID": "docker-pullable://busybox@sha256:061ca9704a714ee3e8b80523ec720c64f6209ad3f97c0ff7cb9ec7d19f15149f",
"lastState": ,
"name": "busybox",
"ready": true,
"restartCount": 0,
"state":
"running":
"startedAt": "2019-03-28T21:09:49Z"



],
"hostIP": "172.17.0.37",
"phase": "Running",
"podIP": "10.32.0.4",
"qosClass": "BestEffort",
"startTime": "2019-03-28T21:09:42Z"




Currently If i need the podIP, then I do that this way to find the object which has the search keyword and then I build the path



curl myson | jq "[paths]" | grep "IP" --context=10


Is there any nice shortcut to simplify this? What I really need is - all the paths which could have the matching key.



spec.podIP
spec.hostIP









share|improve this question
































    0















    I have a deep json. Sometimes, I need to look for the json path for a key containing certain word.




    "apiVersion": "v1",
    "kind": "Pod",
    "metadata":
    "creationTimestamp": "2019-03-28T21:09:42Z",
    "labels":
    "bu": "finance",
    "env": "prod"
    ,
    "name": "auth",
    "namespace": "default",
    "resourceVersion": "2786",
    "selfLink": "/api/v1/namespaces/default/pods/auth",
    "uid": "ce73565a-519d-11e9-bcb7-0242ac110009"
    ,
    "spec":
    "containers": [

    "command": [
    "sleep",
    "4800"
    ],
    "image": "busybox",
    "imagePullPolicy": "Always",
    "name": "busybox",
    "resources": ,
    "terminationMessagePath": "/dev/termination-log",
    "terminationMessagePolicy": "File",
    "volumeMounts": [

    "mountPath": "/var/run/secrets/kubernetes.io/serviceaccount",
    "name": "default-token-dbpcm",
    "readOnly": true

    ]

    ],
    "dnsPolicy": "ClusterFirst",
    "nodeName": "node01",
    "priority": 0,
    "restartPolicy": "Always",
    "schedulerName": "default-scheduler",
    "securityContext": ,
    "serviceAccount": "default",
    "serviceAccountName": "default",
    "terminationGracePeriodSeconds": 30,
    "tolerations": [

    "effect": "NoExecute",
    "key": "node.kubernetes.io/not-ready",
    "operator": "Exists",
    "tolerationSeconds": 300
    ,

    "effect": "NoExecute",
    "key": "node.kubernetes.io/unreachable",
    "operator": "Exists",
    "tolerationSeconds": 300

    ],
    "volumes": [

    "name": "default-token-dbpcm",
    "secret":
    "defaultMode": 420,
    "secretName": "default-token-dbpcm"


    ]
    ,
    "status":
    "conditions": [

    "lastProbeTime": null,
    "lastTransitionTime": "2019-03-28T21:09:42Z",
    "status": "True",
    "type": "Initialized"
    ,

    "lastProbeTime": null,
    "lastTransitionTime": "2019-03-28T21:09:50Z",
    "status": "True",
    "type": "Ready"
    ,

    "lastProbeTime": null,
    "lastTransitionTime": null,
    "status": "True",
    "type": "ContainersReady"
    ,

    "lastProbeTime": null,
    "lastTransitionTime": "2019-03-28T21:09:42Z",
    "status": "True",
    "type": "PodScheduled"

    ],
    "containerStatuses": [

    "containerID": "docker://b5be8275555ad70939401d658bb4e504b52215b70618ad43c2d0d02c35e1ae27",
    "image": "busybox:latest",
    "imageID": "docker-pullable://busybox@sha256:061ca9704a714ee3e8b80523ec720c64f6209ad3f97c0ff7cb9ec7d19f15149f",
    "lastState": ,
    "name": "busybox",
    "ready": true,
    "restartCount": 0,
    "state":
    "running":
    "startedAt": "2019-03-28T21:09:49Z"



    ],
    "hostIP": "172.17.0.37",
    "phase": "Running",
    "podIP": "10.32.0.4",
    "qosClass": "BestEffort",
    "startTime": "2019-03-28T21:09:42Z"




    Currently If i need the podIP, then I do that this way to find the object which has the search keyword and then I build the path



    curl myson | jq "[paths]" | grep "IP" --context=10


    Is there any nice shortcut to simplify this? What I really need is - all the paths which could have the matching key.



    spec.podIP
    spec.hostIP









    share|improve this question




























      0












      0








      0








      I have a deep json. Sometimes, I need to look for the json path for a key containing certain word.




      "apiVersion": "v1",
      "kind": "Pod",
      "metadata":
      "creationTimestamp": "2019-03-28T21:09:42Z",
      "labels":
      "bu": "finance",
      "env": "prod"
      ,
      "name": "auth",
      "namespace": "default",
      "resourceVersion": "2786",
      "selfLink": "/api/v1/namespaces/default/pods/auth",
      "uid": "ce73565a-519d-11e9-bcb7-0242ac110009"
      ,
      "spec":
      "containers": [

      "command": [
      "sleep",
      "4800"
      ],
      "image": "busybox",
      "imagePullPolicy": "Always",
      "name": "busybox",
      "resources": ,
      "terminationMessagePath": "/dev/termination-log",
      "terminationMessagePolicy": "File",
      "volumeMounts": [

      "mountPath": "/var/run/secrets/kubernetes.io/serviceaccount",
      "name": "default-token-dbpcm",
      "readOnly": true

      ]

      ],
      "dnsPolicy": "ClusterFirst",
      "nodeName": "node01",
      "priority": 0,
      "restartPolicy": "Always",
      "schedulerName": "default-scheduler",
      "securityContext": ,
      "serviceAccount": "default",
      "serviceAccountName": "default",
      "terminationGracePeriodSeconds": 30,
      "tolerations": [

      "effect": "NoExecute",
      "key": "node.kubernetes.io/not-ready",
      "operator": "Exists",
      "tolerationSeconds": 300
      ,

      "effect": "NoExecute",
      "key": "node.kubernetes.io/unreachable",
      "operator": "Exists",
      "tolerationSeconds": 300

      ],
      "volumes": [

      "name": "default-token-dbpcm",
      "secret":
      "defaultMode": 420,
      "secretName": "default-token-dbpcm"


      ]
      ,
      "status":
      "conditions": [

      "lastProbeTime": null,
      "lastTransitionTime": "2019-03-28T21:09:42Z",
      "status": "True",
      "type": "Initialized"
      ,

      "lastProbeTime": null,
      "lastTransitionTime": "2019-03-28T21:09:50Z",
      "status": "True",
      "type": "Ready"
      ,

      "lastProbeTime": null,
      "lastTransitionTime": null,
      "status": "True",
      "type": "ContainersReady"
      ,

      "lastProbeTime": null,
      "lastTransitionTime": "2019-03-28T21:09:42Z",
      "status": "True",
      "type": "PodScheduled"

      ],
      "containerStatuses": [

      "containerID": "docker://b5be8275555ad70939401d658bb4e504b52215b70618ad43c2d0d02c35e1ae27",
      "image": "busybox:latest",
      "imageID": "docker-pullable://busybox@sha256:061ca9704a714ee3e8b80523ec720c64f6209ad3f97c0ff7cb9ec7d19f15149f",
      "lastState": ,
      "name": "busybox",
      "ready": true,
      "restartCount": 0,
      "state":
      "running":
      "startedAt": "2019-03-28T21:09:49Z"



      ],
      "hostIP": "172.17.0.37",
      "phase": "Running",
      "podIP": "10.32.0.4",
      "qosClass": "BestEffort",
      "startTime": "2019-03-28T21:09:42Z"




      Currently If i need the podIP, then I do that this way to find the object which has the search keyword and then I build the path



      curl myson | jq "[paths]" | grep "IP" --context=10


      Is there any nice shortcut to simplify this? What I really need is - all the paths which could have the matching key.



      spec.podIP
      spec.hostIP









      share|improve this question
















      I have a deep json. Sometimes, I need to look for the json path for a key containing certain word.




      "apiVersion": "v1",
      "kind": "Pod",
      "metadata":
      "creationTimestamp": "2019-03-28T21:09:42Z",
      "labels":
      "bu": "finance",
      "env": "prod"
      ,
      "name": "auth",
      "namespace": "default",
      "resourceVersion": "2786",
      "selfLink": "/api/v1/namespaces/default/pods/auth",
      "uid": "ce73565a-519d-11e9-bcb7-0242ac110009"
      ,
      "spec":
      "containers": [

      "command": [
      "sleep",
      "4800"
      ],
      "image": "busybox",
      "imagePullPolicy": "Always",
      "name": "busybox",
      "resources": ,
      "terminationMessagePath": "/dev/termination-log",
      "terminationMessagePolicy": "File",
      "volumeMounts": [

      "mountPath": "/var/run/secrets/kubernetes.io/serviceaccount",
      "name": "default-token-dbpcm",
      "readOnly": true

      ]

      ],
      "dnsPolicy": "ClusterFirst",
      "nodeName": "node01",
      "priority": 0,
      "restartPolicy": "Always",
      "schedulerName": "default-scheduler",
      "securityContext": ,
      "serviceAccount": "default",
      "serviceAccountName": "default",
      "terminationGracePeriodSeconds": 30,
      "tolerations": [

      "effect": "NoExecute",
      "key": "node.kubernetes.io/not-ready",
      "operator": "Exists",
      "tolerationSeconds": 300
      ,

      "effect": "NoExecute",
      "key": "node.kubernetes.io/unreachable",
      "operator": "Exists",
      "tolerationSeconds": 300

      ],
      "volumes": [

      "name": "default-token-dbpcm",
      "secret":
      "defaultMode": 420,
      "secretName": "default-token-dbpcm"


      ]
      ,
      "status":
      "conditions": [

      "lastProbeTime": null,
      "lastTransitionTime": "2019-03-28T21:09:42Z",
      "status": "True",
      "type": "Initialized"
      ,

      "lastProbeTime": null,
      "lastTransitionTime": "2019-03-28T21:09:50Z",
      "status": "True",
      "type": "Ready"
      ,

      "lastProbeTime": null,
      "lastTransitionTime": null,
      "status": "True",
      "type": "ContainersReady"
      ,

      "lastProbeTime": null,
      "lastTransitionTime": "2019-03-28T21:09:42Z",
      "status": "True",
      "type": "PodScheduled"

      ],
      "containerStatuses": [

      "containerID": "docker://b5be8275555ad70939401d658bb4e504b52215b70618ad43c2d0d02c35e1ae27",
      "image": "busybox:latest",
      "imageID": "docker-pullable://busybox@sha256:061ca9704a714ee3e8b80523ec720c64f6209ad3f97c0ff7cb9ec7d19f15149f",
      "lastState": ,
      "name": "busybox",
      "ready": true,
      "restartCount": 0,
      "state":
      "running":
      "startedAt": "2019-03-28T21:09:49Z"



      ],
      "hostIP": "172.17.0.37",
      "phase": "Running",
      "podIP": "10.32.0.4",
      "qosClass": "BestEffort",
      "startTime": "2019-03-28T21:09:42Z"




      Currently If i need the podIP, then I do that this way to find the object which has the search keyword and then I build the path



      curl myson | jq "[paths]" | grep "IP" --context=10


      Is there any nice shortcut to simplify this? What I really need is - all the paths which could have the matching key.



      spec.podIP
      spec.hostIP






      json jq






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 28 at 21:21







      KitKarson

















      asked Mar 28 at 21:06









      KitKarsonKitKarson

      1,4213 gold badges19 silver badges44 bronze badges




      1,4213 gold badges19 silver badges44 bronze badges

























          2 Answers
          2






          active

          oldest

          votes


















          1
















          select paths containing keyword in their last element, and use join(".") to generate your desired output.



          paths
          | select(.[-1] | type == "string" and contains("keyword"))
          | join(".")



          • .[-1] returns the last element of an array,


          • type == "string" is required because an array index is a number and numbers and strings can't be checked for their containment.

          You may want to specify -r option.




          As @JeffMercado implicitly suggested you can set the query from command line without touching the script:



          jq -r 'paths
          | select(.[-1] | type == "string" and contains($q))
          | join(".")' file.json --arg q 'keyword'





          share|improve this answer



























          • This is very nice. but curious. what if type is not known!? in the above json, there is a key called command which is not retrieved as it is not string type.

            – KitKarson
            Mar 28 at 21:33











          • @KitKarson as far as I know there is no such thing as unknown type in JSON

            – oguz ismail
            Mar 28 at 21:34






          • 1





            Can you try your example - keyword is command .? It does not show any output

            – KitKarson
            Mar 28 at 21:37











          • It woks great as long as the keyword is simple keyword: value .not if the keyword:[12,23]

            – KitKarson
            Mar 28 at 21:38






          • 1





            man.. you are awesome. I also upvoted couple of your other answers to appreciate your help. Thanks.

            – KitKarson
            Mar 28 at 21:53


















          0
















          You can stream the input in, which provides paths and values. You could then inspect the paths and optionally output the values.



          $ jq --stream --arg pattern 'IP' '
          select(length == 2 and any(.[0][] | strings; test($pattern)))
          | "(.[0] | join(".")): (.[1])"
          ' input.json
          "status.hostIP: 172.17.0.37"
          "status.podIP: 10.32.0.4"





          share|improve this answer


























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );














            draft saved

            draft discarded
















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55406838%2fbuilding-json-path-from-jq-using-some-keyword%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1
















            select paths containing keyword in their last element, and use join(".") to generate your desired output.



            paths
            | select(.[-1] | type == "string" and contains("keyword"))
            | join(".")



            • .[-1] returns the last element of an array,


            • type == "string" is required because an array index is a number and numbers and strings can't be checked for their containment.

            You may want to specify -r option.




            As @JeffMercado implicitly suggested you can set the query from command line without touching the script:



            jq -r 'paths
            | select(.[-1] | type == "string" and contains($q))
            | join(".")' file.json --arg q 'keyword'





            share|improve this answer



























            • This is very nice. but curious. what if type is not known!? in the above json, there is a key called command which is not retrieved as it is not string type.

              – KitKarson
              Mar 28 at 21:33











            • @KitKarson as far as I know there is no such thing as unknown type in JSON

              – oguz ismail
              Mar 28 at 21:34






            • 1





              Can you try your example - keyword is command .? It does not show any output

              – KitKarson
              Mar 28 at 21:37











            • It woks great as long as the keyword is simple keyword: value .not if the keyword:[12,23]

              – KitKarson
              Mar 28 at 21:38






            • 1





              man.. you are awesome. I also upvoted couple of your other answers to appreciate your help. Thanks.

              – KitKarson
              Mar 28 at 21:53















            1
















            select paths containing keyword in their last element, and use join(".") to generate your desired output.



            paths
            | select(.[-1] | type == "string" and contains("keyword"))
            | join(".")



            • .[-1] returns the last element of an array,


            • type == "string" is required because an array index is a number and numbers and strings can't be checked for their containment.

            You may want to specify -r option.




            As @JeffMercado implicitly suggested you can set the query from command line without touching the script:



            jq -r 'paths
            | select(.[-1] | type == "string" and contains($q))
            | join(".")' file.json --arg q 'keyword'





            share|improve this answer



























            • This is very nice. but curious. what if type is not known!? in the above json, there is a key called command which is not retrieved as it is not string type.

              – KitKarson
              Mar 28 at 21:33











            • @KitKarson as far as I know there is no such thing as unknown type in JSON

              – oguz ismail
              Mar 28 at 21:34






            • 1





              Can you try your example - keyword is command .? It does not show any output

              – KitKarson
              Mar 28 at 21:37











            • It woks great as long as the keyword is simple keyword: value .not if the keyword:[12,23]

              – KitKarson
              Mar 28 at 21:38






            • 1





              man.. you are awesome. I also upvoted couple of your other answers to appreciate your help. Thanks.

              – KitKarson
              Mar 28 at 21:53













            1














            1










            1









            select paths containing keyword in their last element, and use join(".") to generate your desired output.



            paths
            | select(.[-1] | type == "string" and contains("keyword"))
            | join(".")



            • .[-1] returns the last element of an array,


            • type == "string" is required because an array index is a number and numbers and strings can't be checked for their containment.

            You may want to specify -r option.




            As @JeffMercado implicitly suggested you can set the query from command line without touching the script:



            jq -r 'paths
            | select(.[-1] | type == "string" and contains($q))
            | join(".")' file.json --arg q 'keyword'





            share|improve this answer















            select paths containing keyword in their last element, and use join(".") to generate your desired output.



            paths
            | select(.[-1] | type == "string" and contains("keyword"))
            | join(".")



            • .[-1] returns the last element of an array,


            • type == "string" is required because an array index is a number and numbers and strings can't be checked for their containment.

            You may want to specify -r option.




            As @JeffMercado implicitly suggested you can set the query from command line without touching the script:



            jq -r 'paths
            | select(.[-1] | type == "string" and contains($q))
            | join(".")' file.json --arg q 'keyword'






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Mar 30 at 12:46

























            answered Mar 28 at 21:26









            oguz ismailoguz ismail

            13k7 gold badges19 silver badges37 bronze badges




            13k7 gold badges19 silver badges37 bronze badges















            • This is very nice. but curious. what if type is not known!? in the above json, there is a key called command which is not retrieved as it is not string type.

              – KitKarson
              Mar 28 at 21:33











            • @KitKarson as far as I know there is no such thing as unknown type in JSON

              – oguz ismail
              Mar 28 at 21:34






            • 1





              Can you try your example - keyword is command .? It does not show any output

              – KitKarson
              Mar 28 at 21:37











            • It woks great as long as the keyword is simple keyword: value .not if the keyword:[12,23]

              – KitKarson
              Mar 28 at 21:38






            • 1





              man.. you are awesome. I also upvoted couple of your other answers to appreciate your help. Thanks.

              – KitKarson
              Mar 28 at 21:53

















            • This is very nice. but curious. what if type is not known!? in the above json, there is a key called command which is not retrieved as it is not string type.

              – KitKarson
              Mar 28 at 21:33











            • @KitKarson as far as I know there is no such thing as unknown type in JSON

              – oguz ismail
              Mar 28 at 21:34






            • 1





              Can you try your example - keyword is command .? It does not show any output

              – KitKarson
              Mar 28 at 21:37











            • It woks great as long as the keyword is simple keyword: value .not if the keyword:[12,23]

              – KitKarson
              Mar 28 at 21:38






            • 1





              man.. you are awesome. I also upvoted couple of your other answers to appreciate your help. Thanks.

              – KitKarson
              Mar 28 at 21:53
















            This is very nice. but curious. what if type is not known!? in the above json, there is a key called command which is not retrieved as it is not string type.

            – KitKarson
            Mar 28 at 21:33





            This is very nice. but curious. what if type is not known!? in the above json, there is a key called command which is not retrieved as it is not string type.

            – KitKarson
            Mar 28 at 21:33













            @KitKarson as far as I know there is no such thing as unknown type in JSON

            – oguz ismail
            Mar 28 at 21:34





            @KitKarson as far as I know there is no such thing as unknown type in JSON

            – oguz ismail
            Mar 28 at 21:34




            1




            1





            Can you try your example - keyword is command .? It does not show any output

            – KitKarson
            Mar 28 at 21:37





            Can you try your example - keyword is command .? It does not show any output

            – KitKarson
            Mar 28 at 21:37













            It woks great as long as the keyword is simple keyword: value .not if the keyword:[12,23]

            – KitKarson
            Mar 28 at 21:38





            It woks great as long as the keyword is simple keyword: value .not if the keyword:[12,23]

            – KitKarson
            Mar 28 at 21:38




            1




            1





            man.. you are awesome. I also upvoted couple of your other answers to appreciate your help. Thanks.

            – KitKarson
            Mar 28 at 21:53





            man.. you are awesome. I also upvoted couple of your other answers to appreciate your help. Thanks.

            – KitKarson
            Mar 28 at 21:53













            0
















            You can stream the input in, which provides paths and values. You could then inspect the paths and optionally output the values.



            $ jq --stream --arg pattern 'IP' '
            select(length == 2 and any(.[0][] | strings; test($pattern)))
            | "(.[0] | join(".")): (.[1])"
            ' input.json
            "status.hostIP: 172.17.0.37"
            "status.podIP: 10.32.0.4"





            share|improve this answer





























              0
















              You can stream the input in, which provides paths and values. You could then inspect the paths and optionally output the values.



              $ jq --stream --arg pattern 'IP' '
              select(length == 2 and any(.[0][] | strings; test($pattern)))
              | "(.[0] | join(".")): (.[1])"
              ' input.json
              "status.hostIP: 172.17.0.37"
              "status.podIP: 10.32.0.4"





              share|improve this answer



























                0














                0










                0









                You can stream the input in, which provides paths and values. You could then inspect the paths and optionally output the values.



                $ jq --stream --arg pattern 'IP' '
                select(length == 2 and any(.[0][] | strings; test($pattern)))
                | "(.[0] | join(".")): (.[1])"
                ' input.json
                "status.hostIP: 172.17.0.37"
                "status.podIP: 10.32.0.4"





                share|improve this answer













                You can stream the input in, which provides paths and values. You could then inspect the paths and optionally output the values.



                $ jq --stream --arg pattern 'IP' '
                select(length == 2 and any(.[0][] | strings; test($pattern)))
                | "(.[0] | join(".")): (.[1])"
                ' input.json
                "status.hostIP: 172.17.0.37"
                "status.podIP: 10.32.0.4"






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 29 at 21:30









                Jeff MercadoJeff Mercado

                98.2k21 gold badges198 silver badges219 bronze badges




                98.2k21 gold badges198 silver badges219 bronze badges































                    draft saved

                    draft discarded















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55406838%2fbuilding-json-path-from-jq-using-some-keyword%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                    은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현