user is posting by AJAX that data package in JS:
var data = new FormData();
data.append("title", title);
data.append("from", from);
data.append("to", to);
data.append("what", what);
data.append("why", why);
data.append("milestones", JSON.stringify(milestones_object));
A milestones object looks like this:
{
"0": {
"0": {
"title": "1",
"favorite": false,
"progress": 0
},
"1": {
"title": "2",
"favorite": true,
"progress": 0
},
"2": {
"title": "3",
"favorite": false,
"progress": 0
},
"title": "a",
"favorite": false
},
"1": {
"0": {
"title": "1",
"favorite": true,
"progress": 0
},
"1": {
"title": "2",
"favorite": false,
"progress": 0
},
"2": {
"title": "3",
"favorite": false,
"progress": 0
},
"3": {
"title": "4",
"favorite": false,
"progress": 0
},
"4": {
"title": "5",
"favorite": false,
"progress": 0
},
"title": "b",
"favorite": true
},
"2": {
"0": {
"title": "4",
"favorite": false,
"progress": 0
},
"1": {
"title": "3",
"favorite": true,
"progress": 0
},
"2": {
"title": "2",
"favorite": false,
"progress": 0
},
"3": {
"title": "1",
"favorite": false,
"progress": 0
},
"title": "c",
"favorite": false
}
}
I want to validate that data in my PHP webservice. There is no problem with standard variables, but what with JSON? What if some angry user will send additional fields that don't match with my project idea? Can we filter that JSON by something like delete_additional_json_fields($json_obj, $fillable_fields)? How to easly validate each property of that JSON? How to work with that in most proper way?
Please for help.