Skip to content

Instantly share code, notes, and snippets.

@eirenik0
Created October 23, 2018 13:16
Show Gist options
  • Save eirenik0/5c3dcc2651488c7d4f0d0f3d0e065306 to your computer and use it in GitHub Desktop.
Save eirenik0/5c3dcc2651488c7d4f0d0f3d0e065306 to your computer and use it in GitHub Desktop.
Get sorted Json from URL where object is zipped Json string
import requests
import io
import gzip
import pyperclip
import json
def get_sorted_json(url):
buff = io.BytesIO()
r = requests.get(url, stream=True)
for chunk in r.iter_content(chunk_size=1024):
if chunk:
buff.write(chunk)
buff.seek(0)
json_obj = json.loads(gzip.GzipFile(fileobj=buff, mode='rb').read())
return json.dumps(json_obj, sort_keys=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment