refactored the json unmarshal code