handle JSON requests and responses