fixed writeJSON