Why pass one parameter as a JSON string and the other as an actual data structure? This seems to be an incongruous approach. As noted above, the "payload" is not JSON at all. I think your main validateJSONPayload() function name and signature is odd. Why uppercase first c in reCursiveCheck()?.Why are you mixing camelCase and snake_case in your code? I know PHP is not very consistent here, but that doesn't mean you shouldn't be - at least within the confines of a single library, class, set of functions, etc.
![php json decode post php json decode post](https://sh14.ru/wp-content/uploads/2020/04/json.png)
Why name a variable $json_payload when it does not contain JSON at all, but rather an object built from JSON? Perhaps $payload is better here.
![php json decode post php json decode post](https://dyedd.cn/usr/uploads/2020/03/4170547611.png)
I am not sure which is more appropriate to your application, but wanted to present both options for putting this logic into a class. This would save you the overhead of having to re-validate the schema with each validation request. $result2 = $validator->validate($jsonPatload2) $result1 = $validator->validate($jsonPayload1) If you find you have one schema that is used multiple times for validation, then perhaps it makes sense to have concrete validator objects like this: $validator = new JsonSchemaValidator($jsonSchema) I would think in this case perhaps only a class with static functions might be needed, so you could make calls against the validator like: $result = JsonSchemaValidator::validate($jsonSchema, $jsonPayload) I would consider moving this into an object-oriented paradigm which is more common in PHP. This in of itself is not "wrong", it is just a little bit unusual in the PHP world. Your solution is very "functional programming" in approach, with nested function declarations and such.
![php json decode post php json decode post](https://www.sourcecodester.com/sites/default/files/2019-09-13_23_33_56-localhost_php_-_insert_data_to_json_file_index.php_.png)
I know there are PHP JSON validators out there, here is a quick one I just rolled up.