{"id":21185266,"url":"https://github.com/yusufnb/verify-json","last_synced_at":"2025-03-17T14:14:05.461Z","repository":{"id":45630862,"uuid":"255802403","full_name":"yusufnb/verify-json","owner":"yusufnb","description":"verify-json","archived":false,"fork":false,"pushed_at":"2021-12-03T23:56:13.000Z","size":21,"stargazers_count":204,"open_issues_count":0,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-04T22:33:44.481Z","etag":null,"topics":["json","json-schema","restful-api","schema-validation"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yusufnb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-04-15T04:14:05.000Z","updated_at":"2024-01-04T16:44:46.000Z","dependencies_parsed_at":"2022-09-04T07:12:42.436Z","dependency_job_id":null,"html_url":"https://github.com/yusufnb/verify-json","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/yusufnb%2Fverify-json","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yusufnb%2Fverify-json/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yusufnb%2Fverify-json/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yusufnb%2Fverify-json/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yusufnb","download_url":"https://codeload.github.com/yusufnb/verify-json/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244047646,"owners_count":20389206,"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":["json","json-schema","restful-api","schema-validation"],"created_at":"2024-11-20T18:15:36.062Z","updated_at":"2025-03-17T14:14:05.420Z","avatar_url":"https://github.com/yusufnb.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Verify JSON\n\nLibrary to verify JSON structure easily using a lightweight JSON schema syntax\n\n# About\n\nThis project results from my need to verify JSON schema in a lightweight manner, without the need for an extensive definition and development code.\n\nThe schema syntax is minimalist and extremely easy to write.\n\n# Installation\n\n```JavaScript\nnpm install -s verify-json\n\nconst verify = require('verify-json')\n\nimport verify from 'verify-json';\n```\n\n# Example\n\n```JavaScript\nconst { verify } = require(\"verify-json\");\n\nlet json = {\n  markers: [\n    {\n      stars: 5,\n      name: 'Rixos The Palm Dubai',\n      location: [25.1212, 55.1535],\n      favorite: true,\n      color: 'red',\n    },\n    {\n      stars: 4,\n      name: 'Shangri-La Hotel',\n      location: [25.2084, 55.2719],\n      color: 'blue',\n    },\n  ],\n};\n\n// \u003ckey\u003e:\u003cvalidator\u003e\n// \u003ckey\u003e:?\u003cvalidator\u003e - uses ? for optional\n// \u003ckey\u003e - required non null attribute of any type\n// Skip all the quotations\nconst schema = `{markers: [{\n      stars:i,\n      name:string,\n      location:[:lat,:long],\n      favorite:?b,\n      color:color\n  }]\n}`;\n\n// customValidators are optional. See built-in validators.\nconst customValidators = {\n  lat: (val) =\u003e val \u003e= -90 \u0026\u0026 val \u003c= 90,\n  long: (val) =\u003e val \u003e= -180 \u0026\u0026 val \u003c= 180,\n  color: (val, args) =\u003e {\n    // demonstrating conditional validations. args = { json, path, parent }\n    return (args.parent.stars === 5 \u0026\u0026 val === 'red') || (args.parent.stars === 4 \u0026\u0026 val === 'blue');\n  },\n};\n\nlet result = verify(json, schema, customValidators);\n\nconsole.log(result); // true\n\njson.markers[0].location[0] = 1000;\njson.markers[0].color = 'blue';\ntry {\n  verify(json, schema, customValidators);\n} catch (error) {\n  console.log('error', error); // json.markers.0.location.0: validation failed, json.markers.0.color: validation failed\n}\n\n\n```\n\n# Built-in Validators\n\nFollowing validators are built in and can be used directly -\n\n```JavaScript\n{\n    string    : _.isString,\n    s         : _.isString,      // alias for string\n    number    : _.isNumber,\n    n         : _.isNumber,      // alias for number\n    boolean   : _.isBoolean,\n    b         : _.isBoolean,     // alias for boolean\n    integer   : _.isInteger,\n    i         : _.isInteger,     // alias for integer\n}\n\n```\n\n# Use as a mixin\n\nSince `lodash` is a dependency, this method is also exposed as a lodash mixin. Once imported anywhere, you can simply use `_.verify` to access it.\n\n```JavaScript\n_.verify(json, schema, customValidators)\n```\n\n# License\n\nMIT © Yusuf Bhabhrawala\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyusufnb%2Fverify-json","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyusufnb%2Fverify-json","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyusufnb%2Fverify-json/lists"}