{"id":15068229,"url":"https://github.com/codeforgeek/payload-validator","last_synced_at":"2025-09-21T17:51:21.846Z","repository":{"id":57321025,"uuid":"50181708","full_name":"codeforgeek/payload-validator","owner":"codeforgeek","description":null,"archived":false,"fork":false,"pushed_at":"2019-08-28T08:03:35.000Z","size":7,"stargazers_count":11,"open_issues_count":5,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-24T14:11:15.182Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/codeforgeek.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-01-22T13:04:37.000Z","updated_at":"2020-04-21T15:00:07.000Z","dependencies_parsed_at":"2022-08-26T01:11:01.336Z","dependency_job_id":null,"html_url":"https://github.com/codeforgeek/payload-validator","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeforgeek%2Fpayload-validator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeforgeek%2Fpayload-validator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeforgeek%2Fpayload-validator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeforgeek%2Fpayload-validator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codeforgeek","download_url":"https://codeload.github.com/codeforgeek/payload-validator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248252659,"owners_count":21072699,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-09-25T01:32:40.724Z","updated_at":"2025-09-21T17:51:16.793Z","avatar_url":"https://github.com/codeforgeek.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# API Payload Validator for Node.js\n\nThis module is developed for cross verifying the structure and data of payload. Currently it supports JSON only. It works this way.\n\n* Provide the incoming payload.\n* Provide the target payload.\n* Choose mandatory fields.\n* Tell whether blank field is allowed or not.\n\nOnce you provide these information, this module will check the structure of JSON Object against the target one. It checks the expected values as well. For.eg if key in payload expects the number and incoming payload contains string value. It also validates following :\n\n* blank value.\n* JSON key missing ( Only if provided mandatory )\n* Data type of keys ( String, number, array, object )\n\n## How to install\n\nYou can install this module by typing\n\n```javascript\nnpm install payload-validator\n```\n\nInclude the module in file.\n\n```javascript\nvar payloadCheck = require('payload-validator');\n```\n\nCall the function using following syntax.\n\n```javascript\n var result = payloadCheck.validator(\n     incomingApiPayload,\n     expectedPayload,\n     mandatory elements array,\n     blank value flag\n    )\n ```\n\nCheck for result.success key in order to know validation failed or not. If its false look for result.response.errorMessage for exact error.\n\n## Example.\n\n### Expected payload\n```javascript\nvar source = {\n    \"someString\" : \"\", // represent string\n    \"someNumber\" : 0, // represent number\n    \"someObject\" : {},\n    \"someArray\"  : []\n}\n```\n### Incoming payload\n\n```javascript\nvar target = {\n    \"someString\" : \"Hello\",\n    \"someNumber\" : 0,\n    \"someObject\" : {},\n    \"someArray\" : [1,2]\n}\n```\n### Validator result.\n\n```javascript\nvar result = payloadCheck.validator(source, target, [\"someNumber\"], true);\nconsole.log(result);\n```\nHere is the result.\n\n```javascript\n{ response:\n   {\n       errorMessage: 'Parameter \\'someObject\\' value passed is blank',\n       errorKey: [ 'someObject' ]\n   },\n  success: false\n}\n```\nIf you pass unexpected data such number but expected is String so you will get error message like this.\n\n```javascript\n{ response:\n   {\n       errorMessage: 'Parameter \\'someString\\' value expected is \\'Number\\'',\n       errorKey: [ 'someString' ]\n   },\n  success: false\n}\n```\nOnce validation is successful you will receive following message.\n\n```javascript\n{\n    elements: {\n        someString: 'Hello',\n        someNumber: 1,\n        someArray: [ {} ]\n    },\n  success: true\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodeforgeek%2Fpayload-validator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodeforgeek%2Fpayload-validator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodeforgeek%2Fpayload-validator/lists"}