Sorting arrays of json objects in this manner, of frequency : I have this type of json object

 

       students = [
                    {
                      "name": "Ana Barbique",
                      "category":"B"
                    }
                    {
                      "name": "Marko Polo",
                      "category":"B"
                     }
                    {
                      "name": "Nick Harper",
                      "category":"A"
                     }
                    ]

What I want it to have a object of this type:

    sum = [
           {
             "category": "A",
              "count" : 1
           }
           {
              "category": "B",
              "count" : 2
           }
          ]

So essentially I want to have the objects of the array have the categories that appear in students and their count. The order doesn't matter. I have not done this before.