I am digitally signing json in javascript to be verified by c++. I am using json spirit to parse the json which uses map
s for json Object
s, so the Object
s need to be sorted in the same way as the c++ map
s.
An Object
can easily be sorted by javascript
function sortObject(o) {
var sorted = {},
key, a = [];
for (key in o) {
if (o.hasOwnProperty(key)) {
a.push(key);
}
}
a.sort();
for (key = 0; key < a.length; key++) {
sorted[a[key]] = o[a[key]];
}
return sorted;
}
however, I am unsure of the exact sorting method that c++ uses.
Is the above code sufficient for javascript to sort Object
keys in the same manner that map
keys are sorted? If not, how can this be done?