Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6114489
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:58:50+00:00 2026-05-23T14:58:50+00:00

I have 1 object coming from the server with multiple properties in which I

  • 0

I have 1 object coming from the server with multiple properties in which I want to hydrate it into a new object, changing the name of 1 property and keeping the rest.

Code:

JSON: { UserId: 1, Name: "Woo", Age: 10 }

The format of the object I want it in:

var newObj = {}
newObj.id = jsonObj.UserId;
//Everything property below here is the same. How can i prevent writing this code?
newObj.Name = jsonObj.Name;
newObj.Age = jsonObj.Age;

What I’m doing is based on this answer, trying to parse some json into a format that requires me to change the name of 1 property.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T14:58:51+00:00Added an answer on May 23, 2026 at 2:58 pm

    For such a simple case, you could do something like:

    var newObj = {id: jsonObj.UserId, Name: jsonObj.Name, Age: jsonObj.Age};
    

    For a more complex object with a large number of fields, you might prefer something like:

    //helper function to clone a given object instance
    function copyObject(obj) {
        var newObj = {};
        for (var key in obj) {
            //copy all the fields
            newObj[key] = obj[key];
        }
    
        return newObj;
    }
    
    
    //now manually make any desired modifications
    var newObj = copyObject(jsonObj);
    newObj.id = newObj.UserId;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have object A which in turn has a property of type Object B
I have object A which contains multiple instances of object B, which in turn
I have a string coming from server. I am identifying a particular substring and
This is a little out there but I have a customer object coming back
I have astring directly coming form the database and I am creating object of
I have replication set up between a sql-server 2005 instance and multiple sql-server 2000
I have an IPhone app that uses webservices to get data from a server.
I have renamed a table in a SQL Server 2008 database, from eL_CourseStepUserNotes to
We have switched from sqlite to FireBird embedded server, because FB seems to support
I am new to both Ruby and Mongo, coming from a C# and SQL

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.