jq filter to aggregate into an object's propertyWhat are Aggregates and PODs and how/why are they special?filtering multiple values in json data to use in D3Filter and Store JSON values in NSArrayThe appropriate way to loop inside a d3 filter (or, how to select multiple features)JSON filter using javascriptHow to filter json using php or jquery?Transform JSON without property namesReplace tags in text file using key-value pairs from JSON fileJson to Json transforms using json surfer or Jolt with varying attribute nameHow to filter complex JSON using jq toolset and regular expressions into new JSON array of objects

What is an equivalently powerful replacement spell for the Yuan-Ti's Suggestion spell?

Calculate the Mean mean of two numbers

how do we prove that a sum of two periods is still a period?

How could indestructible materials be used in power generation?

Different meanings of こわい

Does the Idaho Potato Commission associate potato skins with healthy eating?

Finitely generated matrix groups whose eigenvalues are all algebraic

What is required to make GPS signals available indoors?

Do Iron Man suits sport waste management systems?

What is a Samsaran Word™?

How can saying a song's name be a copyright violation?

Can compressed videos be decoded back to their uncompresed original format?

How to remove border from elements in the last row?

Is this draw by repetition?

Why do I get negative height?

What is the most common color to indicate the input-field is disabled?

What do you call someone who asks many questions?

What does the same-ish mean?

Machine learning testing data

How to compactly explain secondary and tertiary characters without resorting to stereotypes?

Is it "common practice in Fourier transform spectroscopy to multiply the measured interferogram by an apodizing function"? If so, why?

What is the opposite of "eschatology"?

What's the meaning of "Sollensaussagen"?

Unlock My Phone! February 2018



jq filter to aggregate into an object's property


What are Aggregates and PODs and how/why are they special?filtering multiple values in json data to use in D3Filter and Store JSON values in NSArrayThe appropriate way to loop inside a d3 filter (or, how to select multiple features)JSON filter using javascriptHow to filter json using php or jquery?Transform JSON without property namesReplace tags in text file using key-value pairs from JSON fileJson to Json transforms using json surfer or Jolt with varying attribute nameHow to filter complex JSON using jq toolset and regular expressions into new JSON array of objects













1















I need to transform JSON to update a firebase firestore.



My incoming json looks like this:



[
"ItemID": 1,
"Size": 10,
"Price": 5
,

"ItemID": 1,
"Size": 11,
"Price": 7
,

"ItemID": 1,
"Size": 12,
"Price": 10
,

"ItemID": 2,
"Size": 11,
"Price": 15
,

"ItemID": 2,
"Size": 12,
"Price": 20
]


And I need JSON to look like this:



[
"ItemID": 1,
"Price":
"10": 5,
"11": 7,
"12": 10

,

"ItemID": 2,
"Price":
"11": 15,
"12": 20

]


What jq filter do I need to do that please?



My other alternatives are to loop through it in javascript, however I want to make this extendable so the pattern can be added, saved and run.



My other alternative is not to store values as keys, to do something like:



[

"ItemID":1,
"Prices":[
"Size":10, "Price":5
]

]









share|improve this question
























  • Please fix the JSON.

    – peak
    Mar 7 at 21:07















1















I need to transform JSON to update a firebase firestore.



My incoming json looks like this:



[
"ItemID": 1,
"Size": 10,
"Price": 5
,

"ItemID": 1,
"Size": 11,
"Price": 7
,

"ItemID": 1,
"Size": 12,
"Price": 10
,

"ItemID": 2,
"Size": 11,
"Price": 15
,

"ItemID": 2,
"Size": 12,
"Price": 20
]


And I need JSON to look like this:



[
"ItemID": 1,
"Price":
"10": 5,
"11": 7,
"12": 10

,

"ItemID": 2,
"Price":
"11": 15,
"12": 20

]


What jq filter do I need to do that please?



My other alternatives are to loop through it in javascript, however I want to make this extendable so the pattern can be added, saved and run.



My other alternative is not to store values as keys, to do something like:



[

"ItemID":1,
"Prices":[
"Size":10, "Price":5
]

]









share|improve this question
























  • Please fix the JSON.

    – peak
    Mar 7 at 21:07













1












1








1








I need to transform JSON to update a firebase firestore.



My incoming json looks like this:



[
"ItemID": 1,
"Size": 10,
"Price": 5
,

"ItemID": 1,
"Size": 11,
"Price": 7
,

"ItemID": 1,
"Size": 12,
"Price": 10
,

"ItemID": 2,
"Size": 11,
"Price": 15
,

"ItemID": 2,
"Size": 12,
"Price": 20
]


And I need JSON to look like this:



[
"ItemID": 1,
"Price":
"10": 5,
"11": 7,
"12": 10

,

"ItemID": 2,
"Price":
"11": 15,
"12": 20

]


What jq filter do I need to do that please?



My other alternatives are to loop through it in javascript, however I want to make this extendable so the pattern can be added, saved and run.



My other alternative is not to store values as keys, to do something like:



[

"ItemID":1,
"Prices":[
"Size":10, "Price":5
]

]









share|improve this question
















I need to transform JSON to update a firebase firestore.



My incoming json looks like this:



[
"ItemID": 1,
"Size": 10,
"Price": 5
,

"ItemID": 1,
"Size": 11,
"Price": 7
,

"ItemID": 1,
"Size": 12,
"Price": 10
,

"ItemID": 2,
"Size": 11,
"Price": 15
,

"ItemID": 2,
"Size": 12,
"Price": 20
]


And I need JSON to look like this:



[
"ItemID": 1,
"Price":
"10": 5,
"11": 7,
"12": 10

,

"ItemID": 2,
"Price":
"11": 15,
"12": 20

]


What jq filter do I need to do that please?



My other alternatives are to loop through it in javascript, however I want to make this extendable so the pattern can be added, saved and run.



My other alternative is not to store values as keys, to do something like:



[

"ItemID":1,
"Prices":[
"Size":10, "Price":5
]

]






json group-by aggregate jq






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 7 at 22:24









peak

34.5k94361




34.5k94361










asked Mar 7 at 20:50









stampede76stampede76

58611230




58611230












  • Please fix the JSON.

    – peak
    Mar 7 at 21:07

















  • Please fix the JSON.

    – peak
    Mar 7 at 21:07
















Please fix the JSON.

– peak
Mar 7 at 21:07





Please fix the JSON.

– peak
Mar 7 at 21:07












1 Answer
1






active

oldest

votes


















1














After fixing the JSON, the following filter produces the output as shown below:



group_by(.ItemID)
| map( reduce .[] as $x ( .[0] | ItemID;
.Price += ($x | (.Size) ) )


Output:



[

"ItemID": 1,
"Price":
"10": 5,
"11": 7,
"12": 10

,

"ItemID": 2,
"Price":
"11": 15,
"12": 20


]





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/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%2fstackoverflow.com%2fquestions%2f55052588%2fjq-filter-to-aggregate-into-an-objects-property%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









    1














    After fixing the JSON, the following filter produces the output as shown below:



    group_by(.ItemID)
    | map( reduce .[] as $x ( .[0] | ItemID;
    .Price += ($x | (.Size) ) )


    Output:



    [

    "ItemID": 1,
    "Price":
    "10": 5,
    "11": 7,
    "12": 10

    ,

    "ItemID": 2,
    "Price":
    "11": 15,
    "12": 20


    ]





    share|improve this answer



























      1














      After fixing the JSON, the following filter produces the output as shown below:



      group_by(.ItemID)
      | map( reduce .[] as $x ( .[0] | ItemID;
      .Price += ($x | (.Size) ) )


      Output:



      [

      "ItemID": 1,
      "Price":
      "10": 5,
      "11": 7,
      "12": 10

      ,

      "ItemID": 2,
      "Price":
      "11": 15,
      "12": 20


      ]





      share|improve this answer

























        1












        1








        1







        After fixing the JSON, the following filter produces the output as shown below:



        group_by(.ItemID)
        | map( reduce .[] as $x ( .[0] | ItemID;
        .Price += ($x | (.Size) ) )


        Output:



        [

        "ItemID": 1,
        "Price":
        "10": 5,
        "11": 7,
        "12": 10

        ,

        "ItemID": 2,
        "Price":
        "11": 15,
        "12": 20


        ]





        share|improve this answer













        After fixing the JSON, the following filter produces the output as shown below:



        group_by(.ItemID)
        | map( reduce .[] as $x ( .[0] | ItemID;
        .Price += ($x | (.Size) ) )


        Output:



        [

        "ItemID": 1,
        "Price":
        "10": 5,
        "11": 7,
        "12": 10

        ,

        "ItemID": 2,
        "Price":
        "11": 15,
        "12": 20


        ]






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 7 at 21:22









        peakpeak

        34.5k94361




        34.5k94361





























            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%2f55052588%2fjq-filter-to-aggregate-into-an-objects-property%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

            1928 у кіно

            Захаров Федір Захарович

            Ель Греко