update json parsing to be more flexible and report better errors