Most common data points?

Not looking for a total solution here, just maybe a bump in the right direction.

I’m looking to use my JSON data file to sort through records and find the top 5 most occurring values for a few keys. A simple example of my JSON structure:

{
  "loki": {
      "title": "Loki",
      "nickname": "loki",
      "year": 2021,
      "genre": "Drama",
      "Network": "Disney+",
  },
  "theoffice": {
      "title": "The Office",
      "nickname": "theoffice",
      "year": 2005,
      "genre": "Comedy",
      "Network": "NBC"
  },
  "seinfeld": {
      "title": "Seinfeld",
      "nickname": "seinfeld",
      "year": 1989,
      "genre": "Comedy",
      "Network": "NBC",
  }
}

So using the above (but over many more records), I’d like to range through and find the top occurring say, networks. So my output would show something like this given the 3 records above:

  1. NBC
  2. Disney+

Is “find the most occurring string” a thing in Hugo? Or do I need to formulate that elsewhere and then feed it into Hugo?

I think I would range through the data set, and use a local scratch to increment the count on each.

1 Like