Created
October 25, 2021 07:48
-
-
Save FallenMax/e2cea2d860914fb3956e7684a8d13d60 to your computer and use it in GitHub Desktop.
sort json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
const sort = (json)=>{ | |
if(json == null) return null | |
if(Array.isArray(json)) return json.map(sort) | |
if(typeof json === 'object') { | |
let sorted = {} | |
Object.keys(json).sort().forEach(key => { | |
sorted[key] = sort(json[key]) | |
}) | |
return sorted | |
} | |
return json | |
} | |
if (!window.json) { | |
console.info('window.json not found'); | |
} else { | |
window.json_sorted = sort(window.json) | |
console.info('sorted at window.json_sorted (copied):', window.json_sorted) | |
copy(window.json_sorted) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment