Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

138
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda