{"action":"created","issue":{"url":"https://api.github.com/repos/tdegrunt/jsonschema/issues/81","labels_url":"https://api.github.com/repos/tdegrunt/jsonschema/issues/81/labels{/name}","comments_url":"https://api.github.com/repos/tdegrunt/jsonschema/issues/81/comments","events_url":"https://api.github.com/repos/tdegrunt/jsonschema/issues/81/events","html_url":"https://github.com/tdegrunt/jsonschema/issues/81","id":39347976,"number":81,"title":"Method to coerce instance into validation","user":{"login":"Acubed","id":437517,"avatar_url":"https://avatars.githubusercontent.com/u/437517?v=3","gravatar_id":"","url":"https://api.github.com/users/Acubed","html_url":"https://github.com/Acubed","followers_url":"https://api.github.com/users/Acubed/followers","following_url":"https://api.github.com/users/Acubed/following{/other_user}","gists_url":"https://api.github.com/users/Acubed/gists{/gist_id}","starred_url":"https://api.github.com/users/Acubed/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Acubed/subscriptions","organizations_url":"https://api.github.com/users/Acubed/orgs","repos_url":"https://api.github.com/users/Acubed/repos","events_url":"https://api.github.com/users/Acubed/events{/privacy}","received_events_url":"https://api.github.com/users/Acubed/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/tdegrunt/jsonschema/labels/enhancement","name":"enhancement","color":"84b6eb"},{"url":"https://api.github.com/repos/tdegrunt/jsonschema/labels/question","name":"question","color":"cc317c"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2014-08-02T12:15:41Z","updated_at":"2015-12-18T04:57:57Z","closed_at":null,"body":"A useful feature for many applications would be a function that takes a possibly non-validating instance, and \"coerces\" it into validation. Strings would be parsed into integers, if the property is specified as an integer; values would be placed into arrays, if the property is specified as an array; missing properties would be given their default values; and so on.\r\n\r\nThere's many possible use cases for this:\r\n\r\nIn a software that stores instances of schemas, when a user creates a new instance of a schema, I would like them to be presented with a \"minimally validating instance\" for example purposes.\r\n\r\nSimilarly, when a user stores a schema, perhaps make trivial corrections instead of sending back a parse error.\r\n\r\nWhen a URL encoded string from HTML forms, or the proposed enctype=\"application/json\" value for HTML forms, is sent, it's received only as strings. JSON Schema could be used to convert the strings back to the native, correct type.\r\n\r\nFor me, this is also the case with reverse-parsing URI Templates. I can generate URIs of form <http://example.com/uid/{uid}> where `id` is an integer, but if I parse a URI like <http://example.com/uid/4>, the `4` must be converted to an integer before I can query the database. Coercing the object `{\"uid\":\"4\"}` to the schema `{\"properties\":{\"uid\":{\"type\":\"string\"}}}` would eliminate the need to do this explicitly.\r\n\r\nThis seems like an in-scope feature, as it would be most useful as a method on the existing prototype, but super programmer senses tell me this is better done as a separate project/module.\r\n\r\nFeedback welcome."},"comment":{"url":"https://api.github.com/repos/tdegrunt/jsonschema/issues/comments/165673618","html_url":"https://github.com/tdegrunt/jsonschema/issues/81#issuecomment-165673618","issue_url":"https://api.github.com/repos/tdegrunt/jsonschema/issues/81","id":165673618,"user":{"login":"Acubed","id":437517,"avatar_url":"https://avatars.githubusercontent.com/u/437517?v=3","gravatar_id":"","url":"https://api.github.com/users/Acubed","html_url":"https://github.com/Acubed","followers_url":"https://api.github.com/users/Acubed/followers","following_url":"https://api.github.com/users/Acubed/following{/other_user}","gists_url":"https://api.github.com/users/Acubed/gists{/gist_id}","starred_url":"https://api.github.com/users/Acubed/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Acubed/subscriptions","organizations_url":"https://api.github.com/users/Acubed/orgs","repos_url":"https://api.github.com/users/Acubed/repos","events_url":"https://api.github.com/users/Acubed/events{/privacy}","received_events_url":"https://api.github.com/users/Acubed/received_events","type":"User","site_admin":false},"created_at":"2015-12-18T04:57:57Z","updated_at":"2015-12-18T04:57:57Z","body":"Hmm, I'll have to take a closer look at it.\r\n\r\nIf I recall, validity/type coercion was an idea that we sort of thought would be kind of out of scope, but another library could use a lot of the functionality from this one."}}