Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

165
Views
How to display tree view structure with object/array values in reactjs?

The required output is attached below in this question. This code gives the correct result.

import React from 'react';
    const sampleJSON = {
      "object":{
        "id": 1,
        "name": "user1",
        "email": "user1@gmail.com",
      }
    }
    
    function App() {
    
      return (
        <div>
          {
            Object.keys(sampleJSON.object).map((key, i) => (
              <p key={i}>
                <span> {key}</span>
                <span> {sampleJSON.object[key]}</span>
              </p>
            )
         ) }
        </div>
      )
    }
    
    export default App;

Here, in the below code, I have used nested object inside the samplejson. But I could not able to display it on the webpage. What code changes should I make to display nested object in my webpage. Even if I add two or more nested objects inside samplejson, it should display in my webpage.

    import React from 'react';
    
    const sampleJSON = {
  "object":{
    "id": 1,
    "name": "user1",
    "email": "user1@gmail.com",
    "job": {
      "role": "Front end developer",
      "experience": "1 year"
    },
    "location": {
      "city": "Chennai"
    }
  }
}

function App() {

  return (
    <div>
      {
        Object.keys(sampleJSON.object).map((key, i) => (
          <p key={i}>
            <span> {key}</span>
            <span> {sampleJSON.object[key]}</span>
          </p>
        )
     ) }
    </div>
  )
}

export default App;

The output should be like this,

enter image description here

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!