{"action":"created","issue":{"url":"https://api.github.com/repos/epoberezkin/ajv/issues/95","labels_url":"https://api.github.com/repos/epoberezkin/ajv/issues/95/labels{/name}","comments_url":"https://api.github.com/repos/epoberezkin/ajv/issues/95/comments","events_url":"https://api.github.com/repos/epoberezkin/ajv/issues/95/events","html_url":"https://github.com/epoberezkin/ajv/issues/95","id":125075251,"number":95,"title":"Option to allow type coercion/cast/type conversion.","user":{"login":"darrin","id":73746,"avatar_url":"https://avatars.githubusercontent.com/u/73746?v=3","gravatar_id":"","url":"https://api.github.com/users/darrin","html_url":"https://github.com/darrin","followers_url":"https://api.github.com/users/darrin/followers","following_url":"https://api.github.com/users/darrin/following{/other_user}","gists_url":"https://api.github.com/users/darrin/gists{/gist_id}","starred_url":"https://api.github.com/users/darrin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/darrin/subscriptions","organizations_url":"https://api.github.com/users/darrin/orgs","repos_url":"https://api.github.com/users/darrin/repos","events_url":"https://api.github.com/users/darrin/events{/privacy}","received_events_url":"https://api.github.com/users/darrin/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/epoberezkin/ajv/labels/option","name":"option","color":"fef2c0"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":22,"created_at":"2016-01-05T23:18:47Z","updated_at":"2016-01-14T18:53:28Z","closed_at":null,"body":"Hi there - \r\n\r\nThanks so much for writing this fantastic validator!\r\n\r\nI'm using it for POSTed forms with checkboxes and other cases where basically I'd love to support conversion to a different type from a string and (as long as conversion from string works) changing the object in place, allowing validation to continue without errors. \r\n\r\nI realize this is a corruption of pure validation and there would be a performance hit but I suspect there are others out there that would like coercion to work as well. An option to 'allowTypeCoercion' or 'laxMode' could allow transformation of primitives like integers, floats and boolean when a 'string' is found.\r\n\r\nIn the absence of support for this - I'm doing validation of the request.body with string types - and then if I need them manually converting each string to a primitive or other type. Beyond requiring additional code in which there's opportunity for inconsistencies with the schema - errors are found further downstream which we need to ripple upward. Support for this via an attribute would eliminate a bunch of redundant code... \r\n\r\nIt looks like the best I can do currently is to specify a string 'format' to try to enforce a numeric value for example or perhaps an enum to enforce the string 'true', 'false' in the case of a boolean. I might be able to use keywords as described in your documentation to try to make this more consistent.\r\n\r\nAm I missing something that would allow conversion or support this in a more elegant way?  Are there others interested in this sort of thing?\r\n\r\nThanks in advance,\r\n-Darrin"},"comment":{"url":"https://api.github.com/repos/epoberezkin/ajv/issues/comments/171737493","html_url":"https://github.com/epoberezkin/ajv/issues/95#issuecomment-171737493","issue_url":"https://api.github.com/repos/epoberezkin/ajv/issues/95","id":171737493,"user":{"login":"darrin","id":73746,"avatar_url":"https://avatars.githubusercontent.com/u/73746?v=3","gravatar_id":"","url":"https://api.github.com/users/darrin","html_url":"https://github.com/darrin","followers_url":"https://api.github.com/users/darrin/followers","following_url":"https://api.github.com/users/darrin/following{/other_user}","gists_url":"https://api.github.com/users/darrin/gists{/gist_id}","starred_url":"https://api.github.com/users/darrin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/darrin/subscriptions","organizations_url":"https://api.github.com/users/darrin/orgs","repos_url":"https://api.github.com/users/darrin/repos","events_url":"https://api.github.com/users/darrin/events{/privacy}","received_events_url":"https://api.github.com/users/darrin/received_events","type":"User","site_admin":false},"created_at":"2016-01-14T18:53:28Z","updated_at":"2016-01-14T18:53:28Z","body":"Actually on second read - a couple questions:\r\n\r\n    string <-> null ('null' <-> null, '' -> null, other not empty strings should fail to coerce to null)\r\n\r\nWhy bother with this one? Is null a type or a value? Does it hold special significance in the framework?  IMHO null is a valid value for any type - though I guess I'm not sure how this is handled in the JSON schema... so maybe this is a stupid question.\r\n\r\n    number/integer <-> null (0 <-> null, not 0 should fail to coerce to null)\r\n\r\nI do like the idea of '' <-> null. \r\nBUT 0 is clearly NOT null rather '0' --> 0... right?\r\n\r\n"}}