如何创buildtypes为string或null的JSON模式属性

我的模式看起来像这样:

schema: { type: 'object', properties: { id: { type: 'string' } } } 

我想被允许设置string或null,我该怎么做?

您可以使用数组来允许属性为多个types 。 types必须是七个JSON模式基元types之一 。

 { type: 'object', properties: { id: { type: ['string', 'null'] } } }