use json instead of raw error msg output
use err instead of message
Remove excessive encoding