rewrite the logic change to json api