use existing helpers to encode json

fix #974