because i'm going to split it with the comma so it turns into an
array, and so when I sort it, I dont want to sort it according to the
{ and }
zi42 has already given you the correct answer.
But Since you have written as quoted above, looks like what you want is really to sort data and split it in an array; in this case, parsing/splitting it at the comma, etc, is a long way to go about it. Here's another way to think about it:
var data = {foo: 123, bar: <x><y></y></x>, baz: 123};
var key;
var dataSorted = []; // Create an empty array
for (key in data) { // Iterate through each key of the JSON data
dataSorted.push(key);
}
dataSorted.sort();
Now you have the data sorted. When you want to use it, you can use it like this:
for (var i = 0; i < dataSorted.length; i++) {
var key = dataSorted[i];
// Now you do whatever you need with sorted data. eg:
console.log("Key is: " + key + ", value is: " + data[key]);
}