JSFiddle - React, Tailwind, and code Playground
JavaScript
var aaData=[{"country":"USA", "month":"1", "earnings":"1000"}, {"country":"USA", "month":"2", "earnings":"1001"}, {"country":"USA", "month":"3", "earnings":"1002"}, {"country":"Germany", "month":"1", "earnings":"1000"}, {"country":"Germany", "month":"2", "earnings":"1001"}, {"country":"Germany", "month":"3", "earnings":"1002"}]
var result=aaData.reduce(function(o, n){
if (!o.hasOwnProperty(n.country)) o[n.country]={};
o[n.country][n.month]=n.earnings;
return o;
}, {})
console.log(result);