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

184
Visualizações
Add JSON element in existing JSON object

I know JSON does not work by index like an array, but i'm looking for a way to add a new JSON element on a specific position within the JSON object.

Let's say i have an array with JSON objects:

[
    {
        "key": value,
        "key": value,
        "key": value,
    },
    {
        "key": value,
        "key": value,
        "key": value,
    }
]

And i want to add a new element in each JSON object on the second position.

[
    {
        "key": value,
        ** Enter new key/value here **
        "key": value,
        "key": value,
    },
    {
        "key": value,
        ** Enter new key/value here **
        "key": value,
        "key": value,
    }
]

Any ideas on how to accomplish this?

Thanks in advance!

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

JavaScript objects (upon which JSON is based) do not remember insertion order.

If serialization/deserialization is not needed, you can use Map objects, which have key=>value pairs with insertion order.

In case you need to serialize/deserialize, then its better to convert the JSON object, to a JSON array of single pair objects, instead like [{"a":"z"}, {"b":"y"}, {"c","x}] etc.

about 4 years ago · Juan Pablo Isaza Relatório

0

There is no such thing in JSON as order by key or value. It works as key-value-pairs

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