javascriptcontentfulcontent-management

Unable to parse data from database with locale data


I am relatively new to React but I was previously working with the Contentful delivery API and decided to switch to the Content Management API because it better suited my needs. Now when I import all of the fields in my entries they all have what appears to be a locale in front of them. This is what it looks like: {en-US: "textile"} and here is a screenshot of it in the console of the browser:

Screenshot of console output from browser

I'm sure it is a pretty simple fix but for the life of me I cannot figure out how to parse this data and I have been unable to find any help on the Internet. Could someone please help me out, I just want the text that I was able to originally get so easily with the delivery API.


Solution

  • Hoping there is going to be only one key 'en-us' inside each object

    var industry = {'en-us':'textile'};
    var featured = {'en-us':true};
    
    var dbData= {industry,featured};
    var newData = {}
    
    //iterate and extract the values to newData
    
    Object.keys(dbData).forEach(key=>{
      newData[key] = Object.values(dbData[key])[0]
    })
    
    
    console.log(newData)