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

182
Views
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 answers
Answer question

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 Report

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 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!