add exit when returning json, to flush stream