JSFiddle - React, Tailwind, and code Playground

Covert elastic output to plain key value pair

by Nalin Sajwan

JavaScript

let jsonObj = {"aggregations":{"2":{"doc_count_error_upper_bound":0,"sum_other_doc_count":0,"buckets":[{"1":{"value":62},"3":{"doc_count_error_upper_bound":0,"sum_other_doc_count":0,"buckets":[{"1":{"value":56},"key":"Jira","doc_count":138},{"1":{"value":41},"key":"ServiceNow","doc_count":61},{"1":{"value":37},"key":"MetricStream","doc_count":52}]},"key":"DQ Operations","doc_count":251},{"1":{"value":62},"3":{"doc_count_error_upper_bound":0,"sum_other_doc_count":0,"buckets":[{"1":{"value":56},"key":"Informatica Axon","doc_count":113},{"1":{"value":52},"key":"Collibra DGC","doc_count":100}]},"key":"Data Governance","doc_count":213},{"1":{"value":59},"3":{"doc_count_error_upper_bound":0,"sum_other_doc_count":0,"buckets":[{"1":{"value":51},"key":"Trillium","doc_count":80},{"1":{"value":48},"key":"Informatica DQ","doc_count":72}]},"key":"Data Quality","doc_count":152},{"1":{"value":56},"3":{"doc_count_error_upper_bound":0,"sum_other_doc_count":0,"buckets":[{"1":{"value":56},"key":"Dk Discourse","doc_count":129}]},"key":"Collaboration Portal","doc_count":129},{"1":{"value":55},"3":{"doc_count_error_upper_bound":0,"sum_other_doc_count":0,"buckets":[{"1":{"value":38},"key":"Informatica Axon","doc_count":65},{"1":{"value":37},"key":"Collibra DGC","doc_count":59}]},"key":"Data Consumer","doc_count":124},{"1":{"value":39},"3":{"doc_count_error_upper_bound":0,"sum_other_doc_count":0,"buckets":[{"1":{"value":39},"key":"Corporate Training","doc_count":55}]},"key":"Tool Training","doc_count":55},{"1":{"value":27},"3":{"doc_count_error_upper_bound":0,"sum_other_doc_count":0,"buckets":[{"1":{"value":27},"key":"External Agency","doc_count":40}]},"key":"Certifications","doc_count":40},{"1":{"value":27},"3":{"doc_count_error_upper_bound":0,"sum_other_doc_count":0,"buckets":[{"1":{"value":27},"key":"SumTotal","doc_count":34}]},"key":"Compliance Training","doc_count":34}]}}};

function copyJSON (dataToCopy) {
  if (typeof dataToCopy === "object") {
    return...