I am trying to create a schema that validates coordinates depending on the system I am using: Polar, Cartesian or Cylindrical coordinates. My idea was to use an if statement to validate the used coordinates values according to the system used. The
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "array",
"minItems": 3,
"maxItems": 3,
"items":
{
"system":
{
"enum": ["Cartesian", "Cylindric","Spherical"],
"description": "The type of the system"
},
"if":
{
"items":
{
"system":
{
"const": "Cartesian"
}
}
},
"then":
{
"items":
{
"x":
{
"type": "number"
},
"y":
{
"type": "number"
},
"z":
{
"type": "number"
}
},
"required": ["x","y","z"]
} ,
"if":
{
"items":
{
"system":
{
"const": "Spherical"
}
}
},
"then":
{
"items":
{
"r":
{
"type": "number"
},
"theta":
{
"type": "number",
"minimum": "0",
"maximum": "360"
},
"phi":
{
"type": "number",
"minimum": "0",
"maximum": "180"
}
},
"required": ["x","y","z"]
},
"if":
{
"items":
{
"system":
{
"const": "Cylindrical"
}
}
},
"then":
{
"items":
{
"r":
{
"type": "number"
},
"theta":
{
"type": "number",
"minimum": "0",
"maximum": "360"
},
"z":
{
"type": "number"
}
},
"required": ["x","y","z"]
}
}
}
}
In the end I get the following errors:
- End of file expected
- Duplicate object key
Since I am new to JSON can someone please explain what I am missing here?
Aucun commentaire:
Enregistrer un commentaire