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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:59:20+00:00 2026-06-09T03:59:20+00:00

How do i sort this JSON object by first_name? { 1 :{user_id:1, first_name:first_name1, last_name:lastname1,

  • 0

How do i sort this JSON object by first_name?

{
    1  :{user_id:1, first_name:"first_name1", last_name:"lastname1", email:"user1@test.com"},
    7  :{user_id:7, first_name:"user2", last_name:"test2", email:""}, 
    72 :{user_id:72, first_name:"testing343", last_name:"", email:""},
    246:{user_id:246, first_name:"aaa", last_name:"ssss", email:""}
}
  • 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-09T03:59:21+00:00Added an answer on June 9, 2026 at 3:59 am

    First of all, your JSON string is invalid. Clear that up first, you are forced to eval() the string in its current form, JSON.parse() won’t work.


    Object keys are unordered by spec. You can’t statically “sort” key names and freeze them in an object. But you certainly can sort the keynames and operate in that order on their values.

    For instance:

    var json = '{1:{user_id:1, first_name:"first_name1", last_name:"lastname1", email:"user1@test.com"}, 7:{user_id:7, first_name:"user2", last_name:"test2", email:""}, 72:{user_id:72, first_name:"testing343", last_name:"", email:""}, 246:{user_id:246, first_name:"aaa", last_name:"ssss", email:""}}';
    
    json = eval( json );
    
    Object.keys( json ).sort(function( a,b ) {
        return json[a].first_name.localeCompare( json[b].first_name );
    }).forEach(function( key ) {
        console.log( json[key].first_name );
    });
    

    That code assumes the availabilty of an ES5 enabled JS engine or any kind of ES5-shim library.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

first post ever here I'm trying to replicate this sort of JSON object so
I have a function to sort a JSON object that looks like this: function
I'm attempting to sort this JSON object: JSONObject = { command: [{ geobox: [...],
I have a JSON array like this [{Email:someone@some.com,Name:ACO,Groups:[MOD_SW,MOD_PI,MOD_GE],Id:63,Url:aco}, {Email:someone@some.com,Name:Agpo,Groups:[MOD_PI],Id:22,Url:agpo}, {Email:someone@some.com,Name:Akatherm,Groups:[MOD_SW],Id:64,Url:akatherm}, {Email:someone@some.com,Name:Albrand,Groups:[MOD_PI,MOD_GE],Id:23,Url:albrand}] I want to
I'm having JSON object var x=[{@Name:'test 1',@Sort:'1',@Status:'yes'}, {@Name:'test 2',@Sort:'5',@Status:'yes'}, {@Name:'test 3',@Sort:'4',@Status:'no'}, {@Name:'test 5',@Sort:'2',@Status:'no'}] I'm
I want to sort a JSON object/array (shown below as myArray ), upon values
I want to sort a JSON object/array (shown below as myArray ), upon values
http://www.devcurry.com/2010/05/sorting-json-array.html I came across this article, i want few explantions over this article. function
I am trying to render an object as json, including nested attributes and sort
I have a hash very similar to the following JSON object; This is 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.