JSFiddle - React, Tailwind, and code Playground

JavaScript

var data = {
    "aggregations": {
        "index_types": {
            "doc_count_error_upper_bound": 0,
            "sum_other_doc_count": 0,
            "buckets": [
                {
                    "key": "client",
                    "doc_count": 1958205,
                    "not_restricted": {
                        "doc_count": 976465
                    },
                    "restricted": {
                        "doc_count": 981740
                    }
                },
                {
                    "key": "ultimateparent",
                    "doc_count": 1616164,
                    "not_restricted": {
                        "doc_count": 741059
                    },
                    "restricted": {
                        "doc_count": 875105
                    }
                },
                {
                    "key": "facility",
                    "doc_count": 1334963,
                    "not_restricted": {
                        "doc_count": 914090
                    },
                    "restricted": {
                        "doc_count": 420872
                    }
                }
            ]
        }
    }
}

for (var i = 0; i < data.aggregations["index_types"].buckets.length; i++) {
    var obj = data.aggregations["index_types"].buckets[i];
    for (var key in obj) {
        if (typeof obj[key] === "object" && Object.keys(obj[key]).length === 1) {
            //1 property object!
            obj[key] = obj[key][Object.keys(obj[key])[0]];
        } 
    }
}

console.log(data)