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

426
Views
How To Add JSON Value in Existed Nested JSON

its possible for add new value JSON to existed nested JSON ?

My JSON its :

{
"meta": {
    "status": 200,
    "message": "Data retrieval successfully"
},
"data": {
    "id": 1,
    "name": "F4rid arya",
    "created_at": "2022-01-04 02:34:27",
    "updated_at": "2022-01-04 02:34:27",
},
"commision" : 50000
}

I want move the "commision" nested to "data" like this :

{
"meta": {
    "status": 200,
    "message": "Data retrieval successfully"
},
"data": {
    "id": 1,
    "name": "F4rid arya",
    "commision" : 50000
    "created_at": "2022-01-04 02:34:27",
    "updated_at": "2022-01-04 02:34:27",
},
}

This my code for create JSON :

const data = await User.find(id)
                let parsed = ResponseParser.apiItem(data.toJSON())
            
                var jsonCommision = {}
                jsonCommision = {
                    "commision": 15000000
                }
                let assignJson = Object.assign(parsed, jsonCommision)
                return response.status(200).send( assignJson )
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You can assign commission property in obj.data by using Object.assign() method and then remove the outer commission property from the object.

Working Demo :

// Original object
const obj = {
  "meta": {
    "status": 200,
    "message": "Data retrieval successfully"
  },
  "data": {
    "id": 1,
    "name": "F4rid arya",
    "created_at": "2022-01-04 02:34:27",
    "updated_at": "2022-01-04 02:34:27",
  },
  "commission" : 50000
};

// Assigning commission property in obj.data object.
Object.assign(obj.data, { "commission": obj.commission });

// Filtered out commission property from an object.
const { commission, ...myObjectRest} = obj;

// Result
console.log(myObjectRest);

about 4 years ago · Juan Pablo Isaza Report

0

try this

const data = await User.find(id);
let parsed = ResponseParser.apiItem(data.toJSON())

parsed.data.commision=parsed.commision;

delete parsed.commision;

return response.status(200).send( parsed )
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!