I'm setting up an endpoint and I'm expecting to get big JSON requests. Of course, I want to make sure these JSON objects are in the correct format as per my documentation, so that I know when to throw a 400
status code. Here's an example:
{
"name":"John",
"surname":"Smith",
"id_no":82347239,
"residences":[
{
"address":[
"12 Something Road",
"Placeville",
"Countrystan",
"1234"
],
"type":"house"
}
] //etc
}
Currently I'm checking validity by using a massive set of isset()
and is_string()
etc checks. Is there a simpler way to make sure the format matches mine? For instance, can I set up a "template" JSON object and use some function to check that the formats match?