user2584937 user2584937 - 4 months ago 16
JSON Question

JSON .Net generates schema incorrectly (type as an array)

When using the JSON.Net JsonSchemaGenerator to generate JSON Schema for my object:

Public Class Host
Public Property uid() As String
End Class


It generates the type property as an array of strings:

{
"type": "object",
"properties": {
"uid": {
"required": true,
"type": [
"string",
"null"
]
}
}
}


The proper JSON Schema should be:

{
"type": "object",
"properties": {
"uid": {
"required": true,
"type": "string"
}
}
}


Has anyone seen this before?

Answer

It is not an array of strings, it is a nullable string.

{ "type": [ "string", "null" ] } means that a valus is either a string or null. Array of strings would be { "type": "array", "items": { "type": "string" } }