Better code for creating JSON files