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

76
Views
Add a field to a JSON object in javascript

How do you add a field to a json in javascript? I've seen it done with arrays but I need it with a JSON field.

So basically

{
   "hello":"this is cool"
}

into

{
   "hello":"this is cool",
   "hi":"i know"
}
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You can do it like so

const json = {
   "hello":"this is cool"
};

json['hi'] = "i know";

console.log(json);

If JSON is a string you can use JSON.parse() as per MDN web docs JSON.parse().

about 4 years ago · Juan Pablo Isaza Report

0

If you want to do it to JSON, then you can do it like below.

let json = `{
  "key": "value"
}`;

const obj = JSON.parse(json);
obj.website = "Stack Overflow";

json = JSON.stringify(obj);
console.log(json);

However, if you want to do it to a regular object, just simply run the code below.

const obj = {
  key: "value",
};

obj.website = "Stack Overflow";
console.log(obj);

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!