How to write python scripts to analyze JSON APIs and Sort results