Refactor json format detection