refactored duplicated code to JSON payload validation