Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

json-schema: treat undefined values as if they were not present. #208

Open
brennie opened this issue Apr 6, 2022 · 1 comment
Open

json-schema: treat undefined values as if they were not present. #208

brennie opened this issue Apr 6, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@brennie
Copy link

brennie commented Apr 6, 2022

It would be nice to have the option to treat undefined values as if they were not present, so a schema like

{
  "type": "object",
  "properties": {
    "foo": {
      "type": "string"
    }
  },
  "additionalProperties": false
}

would match objects like {"foo": undefined} in addition to {} (since the foo key will be omitted when the object is serialized to JSON.

As a workaround, I'm doing JSON.parse(JSON.stringify(obj)) when obj may have undefined keys, which is less than ideal.

@jdanyow jdanyow added the enhancement New feature or request label May 1, 2022
@cosbgn
Copy link

cosbgn commented Aug 17, 2023

Ideally we would have a coercion option like https://ajv.js.org/coercion.html - It would solve this as well as fix things like "true" -> true, "23" -> 23, undefined -> null, etc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants