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.