Refactor JSON filtering