# Null type support

**URL:** <https://jsonforms.discourse.group/t/null-type-support/331>\
**Category:** General\
**Created:** [August 11, 2021, 11:50am UTC](https://jsonforms.discourse.group/t/null-type-support/331 "2021-08-11T11:50:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![yaffol](https://yyz2.discourse-cdn.com/free1/user_avatar/jsonforms.discourse.group/yaffol/32/95_2.png) [@yaffol](https://jsonforms.discourse.group/u/yaffol)\
**Post date:** [August 11, 2021, 11:50am UTC](https://jsonforms.discourse.group/t/null-type-support/331/1 "2021-08-11T11:50:12Z")

</div>

Hi, I have a question about schema support in the React Material renderer - I’m trying out JSON Forms / React for a project, and the schema has a lot of entries like this:

```auto
"name": {
  "oneOf": [
    {
      "type": "null"
    },
    {
      "type": "string"
    }
  ]
}

```

Which causes the renderer to return an error Error: Unknown type: {“type”:“null”}  
And I see that [uischema.ts](https://github.com/eclipsesource/jsonforms/blob/ba6bdc5a93044a872285cd71ed40d9a54f437561/packages/core/src/generators/uischema.ts#L200) doesn’t account for a null type.

I’m wondering - is this a design decision? I would look at adding the type to the core package (not sure how the renderer sets would expect to handle a ‘null’ type, however), or change the schema to something like

```auto
"name": {
  "type": ["string", "null"]
}

```

Which does render better. It feels like this with a combination of validation rules should handle the use case - effectively wanting to have a nullable field - but I wanted to make sure I wasn’t missing something with the `"type": null` support.

---

<div class="post-metadata">

**Author:** ![sdirix](https://yyz2.discourse-cdn.com/free1/user_avatar/jsonforms.discourse.group/sdirix/32/1073_2.png) [@sdirix](https://jsonforms.discourse.group/u/sdirix)\
**Post date:** [August 11, 2021, 12:51pm UTC](https://jsonforms.discourse.group/t/null-type-support/331/2 "2021-08-11T12:51:05Z")

</div>

Hi @yaffol!

so far `type: "null"` has been given a second-rate treatment as it’s not a common type found in schemas which specifically describe forms. It seems that at least the `OneOfRenderer` doesn’t handle it correctly as well as that we have no specific renderer for a `type: "null"` input.

The React Material renderers by default place `undefined` in the data object whenever an element is “deleted”, e.g. when the clear button is executed in the String inputs.

The renderers could be extended to check for additional types like you outlined, i.e. when `"null"` is defined as an additional type they could place `null` instead of `undefined` in the data object.

```auto
"name": {
  "type": ["string", "null"]
}

```

If you’d like to have this behavior without the modification of JSON Forms itself you can do this via custom renderers. You can basically reuse the existing renderers but modify the `handleChange` method given to them to place `null` instead of `undefined` in the data.

Of course the same support could be given to the two-element `oneOf` and `anyOf` constructs as they are semantically the same (as long as the entries are unqiue).
