Refactor JSON to use only pure functions