Support python 2 and 3 writing JSON to file. Use r.text instead of r.content for consistency