remove duplicate code for json