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 8205941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:28:19+00:00 2026-06-07T08:28:19+00:00

I had received a json snippet, which has the following lines (string converted to

  • 0

I had received a json snippet, which has the following lines (string converted to json object)

"profile":{"id":"billg","name":"Bill Gates","countryCode":"US"}

now user adds one more profile, i need to convert profile object to an array of profile objects.

"profile":[{"id":"billg","name":"Bill Gates","countryCode":"US"},{"id":"steve","name":"Steve Jobs","countryCode":"US"}]

Any pointers or code is highly appreciated

  • 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-06-07T08:28:21+00:00Added an answer on June 7, 2026 at 8:28 am

    It would be really great if you show some code of yours: we basically don’t know what’s the source of this json string (JSON = JavaScript Object Notation, so ‘JSON object’ is a tautology), and we don’t know how is the second profile created.

    Consider this, though:

    var jsonData = '{"profile":{"id":"billg","name":"Bill Gates","countryCode":"US"}}';
    var data     = JSON.parse(jsonData); // it's an object now...
    var profile  = data.profile;         // storing another object as a value of `.profile` property
    var anotherProfile = {"id":"steve","name":"Steve Jobs","countryCode":"US"};
    if (! profile[0]) { // checking whether it's an array or not
       // it's not, so we should make an array, adding another profile as well
       data.profile = [data.profile, anotherProfile]; 
    }
    else { // but if it was, it'd be enough just to push anotherProfile into the end of it
       data.profile.push(anotherProfile);
    }
    console.log(data);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For deserialising a json object, I had to define a parent class that would
Had received a module from CCAVENUE and it was working fine with Magento 1.6.2...
I have a project that's using git. When I received the repo, it had
Had this working; at one stage. The problem is the following text is now
I recently asked a question (and had it answered) here: jQuery Load JSON I
I have a JSON object with an array of updates, where each update consists
I had an pre-interview task, which I have completed and the solution works, however
[{name:Mark,Surname:Gaux}] [{Job:2,Type:Office}] I have this JSON echoed by a PHP file on the server
I am really struggling deserializing a PHP json encoded string in ASP.NET. I am
A while back i had a question about why my socket sometimes received only

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.