move json dump out of else clause