One of the main reasons why I'm so reluctant to "let go" of XML is the fact that I love XSDs/Schemas. I love specifying what element types are allowed in my XML files, what attributes they need to have, which attributes are optional, default values for the attributes, legal child elements, etc.
My understanding (and I could be dead wrong) is that JSON simply doesn't have this concept. So let's say I want my new RESTful web service to accept data like so:
"sandwich": {
"type": "PB and J",
"bread": "Marble Rye",
"sliced": "DIAGONAL"
}
It would be nice, from a validation standpoint, if I could specify a "Schema" for this JSON such that someone can't send me:
"car": {
"make": "VW",
"model": "Jetta",
"color": "Silver"
}
This would "fail" validation, since they're sending me a "car" and not a "sandwich". It would also be wonderful to have fine-grain control over the validation of all values, attributes and nested objects that the JSON document might contain; just like I get with XSD.
So I ask: does JSON have anything like this? If not, why?!?! If so, what?
If I could find a viable JSON-based schema validation mechanism, I would happily convert from XML to JSON.
No comments:
Post a Comment