Accessing a nested JSON object to read into a table in React [closed]

I have a JSON object which I'm trying to parse into a table using React, however I'm having trouble using .map() to try to create a row for every unique combination of course code, name, transferable_credits, transferable_credits -> institution, transferable_credits -> name, and url. I can't seem to figure out how to get the key-values of the nested arrays within each JSON root key-value pair.

My React component so far:

import data from './data.json'

const Home = () => {

    return ( 
        <div className="home">
            <table>
                <thead>
                    <tr>
                        <th>Course Code</th>
                        <th>Vendor Institution</th>
                        <th>Vendor Course</th>
                    </tr>
                </thead>
            <tbody>
                {Object.keys(data).map(function(key, index) {
                    return (
                        <tr key={index}>
                            <td>{key}</td>
                            {Object.keys(data[key].transferable_credits).forEach(function(key2) {
                                return (
                                    <td>{key2.institution}</td>
                                )
                            })}
                        </tr>
                    )})

                }
            </tbody>
            </table>
        </div>

     );
}
 
export default Home;
Answer

data[key].transferable_credits is a list so you should loop using map not Object.keys. Try this

import data from './data.json'

const Home = () => {

    return ( 
        <div className="home">
            <table>
                <thead>
                    <tr>
                        <th>Course Code</th>
                        <th>Vendor Institution</th>
                        <th>Vendor Course</th>
                    </tr>
                </thead>
            <tbody>
                {Object.keys(data).map(function(key, index) {
                    return (
                        <tr key={index}>
                            <td>{key}</td>
                            {data[key].transferable_credits.map(function(key2) {
                                return (
                                    <td>{key2.institution}</td>
                                )
                            })}
                        </tr>
                    )})

                }
            </tbody>
            </table>
        </div>

     );
}
 
export default Home;
New contributor
gianpiero papappicco is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.