'How to convert the below SQL Data to the below given JSON data

I'm getting the below data from SQL.

Person  Occupation  Salary  Count
Ajay    Farmer      5000    1
Ajay    Barber      6000    1
Ajay    Carpenter   8000    1
Mahesh  Farmer      3000    1
Mahesh  Barber      8000    1
Mahesh  Carpenter   9000    1

I need to convert it to the following JSON format: I tried but am failing at applying proper groups.

{
  "Ajay": [
    {
      "Job Details": [
        {
          "Occupation": "Farmer",
          "Salary": "5000",
          "count": 1
        },
        {
          "Occupation": "Barber",
          "Salary": "6000",
          "count": 1
        },
        {
          "Occupation": "Carpenter",
          "Salary": "8000",
          "count": 1
        }
      ]
    }
  ],
  "Mahesh": [
    {
      "Job Details": [
        {
          "Occupation": "Farmer",
          "Salary": "3000",
          "count": 1
        },
        {
          "Occupation": "Barber",
          "Salary": "8000",
          "count": 1
        },
        {
          "Occupation": "Carpenter",
          "Salary": "9000",
          "count": 1
        }
      ]
    }
  ]
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source