use json instead of raw error msg output

please review @DeepDiver1975 @karlitschek @VicDeo