I'm noob to json. While defining the format of my RESTful API's result (viz JSON), I felt it would be easier to document it as my own JSON schema. While writing one I had few questions:
- In my result JSON, how do I specify the URI to teh schema it confirms to?
--edit-- is it using
$schema
attribute? - Are there any conventions/guidelines for JSON schema versioning? Are there some attributes that I should/can define inside my schema as attributes? I see JSON schema itself has no version defined except in it's URI specified as value of key
$schema
. - Can I break down my one BIG JSON schema into multiple smaller ones and include one in another? Like #include in C++, then refer to multiple schemas in the JSON I sent to user as result.
- Can I define a custom value for key "type"? E.g. I would like to reuse the definition of "date" like this:
[ignore this line, it's to get the formatting working for following json..]
{
"date":{
"type":"object",
"properties":{
"month":{
"type":"integer",
"minimum":1,
"maximum":12
},
"year":{
"type":"integer",
"minimum":0
}
}
},
"personInfo":{
"type":"object",
"properties":{
"name":{
"type":"string"
},
"dateOfBirth":{
"type":"date"
}
}
},
"student":{
"type":"object",
"properties":{
"id":{
"type":"personInfo"
},
"pass_out_year":{
"type":"date"
}
}
}
}
instead of providing properties of "date" in multiple places like this:
{
"personInfo":{
"type":"object",
"properties":{
"name":{
"type":"string"
},
"dateOfBirth":{
"type":"object",
"properties":{
"month":{
"type":"integer",
"minimum":1,
"maximum":12
},
"year":{
"type":"integer",
"minimum":0
}
}
}
}
},
"student":{
"type":"object",
"properties":{
"id":{
"type":"personInfo"
},
"pass_out_year":{
"type":"object",
"properties":{
"month":{
"type":"integer",
"minimum":1,
"maximum":12
},
"year":{
"type":"integer",
"minimum":0
}
}
}
}
}
}
according to 5.1 type in the spec, it's not possible, but it seems like such a basic usecase!