Output json format, fix crash due to stream closed before all threads completed