Refactor JSON support