jq get attribute of nested object

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












1















I have the following structure (full file example here):





"weather": [

"advertiser": "Worldwide Forecasts",
"notificationText": "Weather - Check the Weather Now - Weather",
"notificationURL": "http://www.worldwideforecasts.com/b/index.html?aff_sub=NL01R15178755321634q5X2zHqXo1976US&utm_term=weather&utm_campaign=bing&utm_content=new-weather%20-%20Weather%20-%202&utm_medium=Search_SEM&utm_source=7&nlhash=BR6et8ISl5dCdAHF&requestId=NL01R15178755321634q5X2zHqXo1976US",
"uuid": "9f27d258-f9d5-4b19-9f70-291eb9cbab51",
"creativeSetId": "2799cbab-1fa1-4f15-bbc9-c92381dbfc57"
,

"advertiser": "Worldwide Forecasts",
"notificationText": "Weather - Check the Weather Now - Weather",
"notificationURL": "http://www.worldwideforecasts.com/b/index.html?aff_sub=NL01R15178755321634q5X2zHqXo1976US&utm_term=weather&utm_campaign=bing&utm_content=new-weather%20-%20Weather%20-%202&utm_medium=Search_SEM&utm_source=7&nlhash=BR6et8ISl5dCdAHF&requestId=NL01R15178755321634q5X2zHqXo1976US",
"uuid": "9f27d258-f9d5-4b19-9f70-291eb9cbab51",
"creativeSetId": "2799cbab-1fa1-4f15-bbc9-c92381dbfc57"

]




With several categories like the weather example.



I want to use jq to get a list of all values for notificationURL so that I'm left with a list of the URLs for all advertisers.



I was initially thinking I could do something like:



cat file.json | jq ...notificationURL


But this doesn't work.



Can anyone assist with the correct way to do this?










share|improve this question


























    1















    I have the following structure (full file example here):





    "weather": [

    "advertiser": "Worldwide Forecasts",
    "notificationText": "Weather - Check the Weather Now - Weather",
    "notificationURL": "http://www.worldwideforecasts.com/b/index.html?aff_sub=NL01R15178755321634q5X2zHqXo1976US&utm_term=weather&utm_campaign=bing&utm_content=new-weather%20-%20Weather%20-%202&utm_medium=Search_SEM&utm_source=7&nlhash=BR6et8ISl5dCdAHF&requestId=NL01R15178755321634q5X2zHqXo1976US",
    "uuid": "9f27d258-f9d5-4b19-9f70-291eb9cbab51",
    "creativeSetId": "2799cbab-1fa1-4f15-bbc9-c92381dbfc57"
    ,

    "advertiser": "Worldwide Forecasts",
    "notificationText": "Weather - Check the Weather Now - Weather",
    "notificationURL": "http://www.worldwideforecasts.com/b/index.html?aff_sub=NL01R15178755321634q5X2zHqXo1976US&utm_term=weather&utm_campaign=bing&utm_content=new-weather%20-%20Weather%20-%202&utm_medium=Search_SEM&utm_source=7&nlhash=BR6et8ISl5dCdAHF&requestId=NL01R15178755321634q5X2zHqXo1976US",
    "uuid": "9f27d258-f9d5-4b19-9f70-291eb9cbab51",
    "creativeSetId": "2799cbab-1fa1-4f15-bbc9-c92381dbfc57"

    ]




    With several categories like the weather example.



    I want to use jq to get a list of all values for notificationURL so that I'm left with a list of the URLs for all advertisers.



    I was initially thinking I could do something like:



    cat file.json | jq ...notificationURL


    But this doesn't work.



    Can anyone assist with the correct way to do this?










    share|improve this question
























      1












      1








      1








      I have the following structure (full file example here):





      "weather": [

      "advertiser": "Worldwide Forecasts",
      "notificationText": "Weather - Check the Weather Now - Weather",
      "notificationURL": "http://www.worldwideforecasts.com/b/index.html?aff_sub=NL01R15178755321634q5X2zHqXo1976US&utm_term=weather&utm_campaign=bing&utm_content=new-weather%20-%20Weather%20-%202&utm_medium=Search_SEM&utm_source=7&nlhash=BR6et8ISl5dCdAHF&requestId=NL01R15178755321634q5X2zHqXo1976US",
      "uuid": "9f27d258-f9d5-4b19-9f70-291eb9cbab51",
      "creativeSetId": "2799cbab-1fa1-4f15-bbc9-c92381dbfc57"
      ,

      "advertiser": "Worldwide Forecasts",
      "notificationText": "Weather - Check the Weather Now - Weather",
      "notificationURL": "http://www.worldwideforecasts.com/b/index.html?aff_sub=NL01R15178755321634q5X2zHqXo1976US&utm_term=weather&utm_campaign=bing&utm_content=new-weather%20-%20Weather%20-%202&utm_medium=Search_SEM&utm_source=7&nlhash=BR6et8ISl5dCdAHF&requestId=NL01R15178755321634q5X2zHqXo1976US",
      "uuid": "9f27d258-f9d5-4b19-9f70-291eb9cbab51",
      "creativeSetId": "2799cbab-1fa1-4f15-bbc9-c92381dbfc57"

      ]




      With several categories like the weather example.



      I want to use jq to get a list of all values for notificationURL so that I'm left with a list of the URLs for all advertisers.



      I was initially thinking I could do something like:



      cat file.json | jq ...notificationURL


      But this doesn't work.



      Can anyone assist with the correct way to do this?










      share|improve this question














      I have the following structure (full file example here):





      "weather": [

      "advertiser": "Worldwide Forecasts",
      "notificationText": "Weather - Check the Weather Now - Weather",
      "notificationURL": "http://www.worldwideforecasts.com/b/index.html?aff_sub=NL01R15178755321634q5X2zHqXo1976US&utm_term=weather&utm_campaign=bing&utm_content=new-weather%20-%20Weather%20-%202&utm_medium=Search_SEM&utm_source=7&nlhash=BR6et8ISl5dCdAHF&requestId=NL01R15178755321634q5X2zHqXo1976US",
      "uuid": "9f27d258-f9d5-4b19-9f70-291eb9cbab51",
      "creativeSetId": "2799cbab-1fa1-4f15-bbc9-c92381dbfc57"
      ,

      "advertiser": "Worldwide Forecasts",
      "notificationText": "Weather - Check the Weather Now - Weather",
      "notificationURL": "http://www.worldwideforecasts.com/b/index.html?aff_sub=NL01R15178755321634q5X2zHqXo1976US&utm_term=weather&utm_campaign=bing&utm_content=new-weather%20-%20Weather%20-%202&utm_medium=Search_SEM&utm_source=7&nlhash=BR6et8ISl5dCdAHF&requestId=NL01R15178755321634q5X2zHqXo1976US",
      "uuid": "9f27d258-f9d5-4b19-9f70-291eb9cbab51",
      "creativeSetId": "2799cbab-1fa1-4f15-bbc9-c92381dbfc57"

      ]




      With several categories like the weather example.



      I want to use jq to get a list of all values for notificationURL so that I'm left with a list of the URLs for all advertisers.



      I was initially thinking I could do something like:



      cat file.json | jq ...notificationURL


      But this doesn't work.



      Can anyone assist with the correct way to do this?







      jq






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Dec 31 '18 at 0:44









      Philip KirkbridePhilip Kirkbride

      2,4212984




      2,4212984




















          1 Answer
          1






          active

          oldest

          votes


















          3














          You have two basic options here (with your full file):



          jq '.categories.notificationURL' bundle.json
          jq '.categories | ..notificationURL' bundle.json


          In the first, you apply the operation twice in succession, and in the second you compose two separate filters together with the pipe operator. I find using extra pipes a lot easier to work with and debug, but these are both identical for your purpose.



          . generic iteration always applies to the single input value of this iteration, so it has to be the first element in an expression and is a syntax error anywhere else, but applied to a specific value to its left-hand side is fine anywhere.



          The very fact that you can write abc at all, rather than only ., is not well-described in the jq documentation, but you can. You can think of . as applying to the identity filter ., although I think it is actually a special case.




          In this exact case you can shrink it down to:



          jq '..notificationURL' bundle.json


          which applies the iterator operation thrice in a row, since there's only the one key "categories" in the top-level object.






          share|improve this answer






















            Your Answer








            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "106"
            ;
            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: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            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/3.0/"u003ecc by-sa 3.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%2funix.stackexchange.com%2fquestions%2f491669%2fjq-get-attribute-of-nested-object%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            3














            You have two basic options here (with your full file):



            jq '.categories.notificationURL' bundle.json
            jq '.categories | ..notificationURL' bundle.json


            In the first, you apply the operation twice in succession, and in the second you compose two separate filters together with the pipe operator. I find using extra pipes a lot easier to work with and debug, but these are both identical for your purpose.



            . generic iteration always applies to the single input value of this iteration, so it has to be the first element in an expression and is a syntax error anywhere else, but applied to a specific value to its left-hand side is fine anywhere.



            The very fact that you can write abc at all, rather than only ., is not well-described in the jq documentation, but you can. You can think of . as applying to the identity filter ., although I think it is actually a special case.




            In this exact case you can shrink it down to:



            jq '..notificationURL' bundle.json


            which applies the iterator operation thrice in a row, since there's only the one key "categories" in the top-level object.






            share|improve this answer



























              3














              You have two basic options here (with your full file):



              jq '.categories.notificationURL' bundle.json
              jq '.categories | ..notificationURL' bundle.json


              In the first, you apply the operation twice in succession, and in the second you compose two separate filters together with the pipe operator. I find using extra pipes a lot easier to work with and debug, but these are both identical for your purpose.



              . generic iteration always applies to the single input value of this iteration, so it has to be the first element in an expression and is a syntax error anywhere else, but applied to a specific value to its left-hand side is fine anywhere.



              The very fact that you can write abc at all, rather than only ., is not well-described in the jq documentation, but you can. You can think of . as applying to the identity filter ., although I think it is actually a special case.




              In this exact case you can shrink it down to:



              jq '..notificationURL' bundle.json


              which applies the iterator operation thrice in a row, since there's only the one key "categories" in the top-level object.






              share|improve this answer

























                3












                3








                3







                You have two basic options here (with your full file):



                jq '.categories.notificationURL' bundle.json
                jq '.categories | ..notificationURL' bundle.json


                In the first, you apply the operation twice in succession, and in the second you compose two separate filters together with the pipe operator. I find using extra pipes a lot easier to work with and debug, but these are both identical for your purpose.



                . generic iteration always applies to the single input value of this iteration, so it has to be the first element in an expression and is a syntax error anywhere else, but applied to a specific value to its left-hand side is fine anywhere.



                The very fact that you can write abc at all, rather than only ., is not well-described in the jq documentation, but you can. You can think of . as applying to the identity filter ., although I think it is actually a special case.




                In this exact case you can shrink it down to:



                jq '..notificationURL' bundle.json


                which applies the iterator operation thrice in a row, since there's only the one key "categories" in the top-level object.






                share|improve this answer













                You have two basic options here (with your full file):



                jq '.categories.notificationURL' bundle.json
                jq '.categories | ..notificationURL' bundle.json


                In the first, you apply the operation twice in succession, and in the second you compose two separate filters together with the pipe operator. I find using extra pipes a lot easier to work with and debug, but these are both identical for your purpose.



                . generic iteration always applies to the single input value of this iteration, so it has to be the first element in an expression and is a syntax error anywhere else, but applied to a specific value to its left-hand side is fine anywhere.



                The very fact that you can write abc at all, rather than only ., is not well-described in the jq documentation, but you can. You can think of . as applying to the identity filter ., although I think it is actually a special case.




                In this exact case you can shrink it down to:



                jq '..notificationURL' bundle.json


                which applies the iterator operation thrice in a row, since there's only the one key "categories" in the top-level object.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Dec 31 '18 at 1:25









                Michael HomerMichael Homer

                46.5k8122161




                46.5k8122161



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Unix & Linux Stack Exchange!


                    • 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%2funix.stackexchange.com%2fquestions%2f491669%2fjq-get-attribute-of-nested-object%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

                    How to check contact read email or not when send email to Individual?

                    Displaying single band from multi-band raster using QGIS

                    How many registers does an x86_64 CPU actually have?