
Announcements
Hello,
I want to parse a JSON object that I'm getting from a query, and the variables in this JSON object are numbers, but that might be NaN. How can I define the schema for this JSON? If I use the returned object with "NaN", it will set the schema to "string", but if the returned value is "101" the schema will be set to "number", the two of them being not compatible.
For instance, if my query returns this object:
{
"countStudents": 50,
"countRooms": 10
}
Then the generated schema type will be
{
"type": "object",
"properties": {
"countStudents": {
"type": "number"
},
"countRooms": {
"type": "number
}
}
But if it returns
{
"countStudents": "Nan",
"countRooms": 10
}
Then the schema will be
{
"type": "object",
"properties": {
"countStudents": {
"type": "string"
},
"countRooms": {
"type": "number
}
}
Is there any way I can create a Schema valid for both? That is, can a property have several types?
Found the solution myself a couple of minutes later: A schema can have several type definitions for a variable, you just have to set the schema property like this:
{
...
"countStudents": {
"type": ["string", "number"]
}
...