Add util package tests for api error, api resource and json
  * Also refactored some of the error writer and generation functions