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

136
Views
How to structure json object for javascript project

I am creating a data structure for my project. It uses json. I am trying to make it easy to search or EDIT the json object. Which structure would be standard. Is there a right or wrong why for would it be okay for me to use either

object with id 2 has parent which is id 1

const items = [
    {
        id: 1,
        title: 'First',
        UUID: 123,
        action : null,
        isFolder: true,
        parent: null,
    },
    {
        id: 2,
        title: 'Second',
        UUID: 123,
        action : null,
        isFolder: false,
        parent: 1,
    },
    {
        id: 3,
        title: 'Third',
        UUID: 123,
        action : null,
        isFolder: false
        parent: null,
    },
]

structure 2

const items = [
    {
        id: 1,
        title: 'First',
        UUID: 123,
        action : null,
        isFolder: true,
        children: [      
            {
                id: 2,
                title: 'Second',
                UUID: 123,
                action : null,
                isFolder: false,
                children: [],
            },
                ]
    },
    {
        id: 3,
        title: 'Third',
        UUID: 123,
        action : null,
        isFolder: false
        children: [],
    },
]
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Option 1. Why? It's the simplest structure, it will be easy to edit individual nodes, to search, to be read by a human (imagine a model where your children have children have children and it gets hard to look at). Also, you should consider what has to happen if you want to change a parent? What if in the future you need to support multiple parents?

At the end of the day you could probably make arguments for either, so you need to choose what you think fits your application, use case, etc. Do you have any idea of what future enhancements might look like? Consider those.

about 4 years ago · Juan Pablo Isaza Report
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!