![php json decode api result php json decode api result](https://d33wubrfki0l68.cloudfront.net/a129732ec0477779859a0a4dd3ec09a586502d0c/5dc05/img/php/curl_init.png)
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 api result php json decode api result](https://i.stack.imgur.com/piN9s.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 api result php json decode api result](https://1.bp.blogspot.com/-tr3IvKB8y1M/XRWzwfAbFwI/AAAAAAAAMHU/G7-4xybHw5g6yi04rG1erV6okwOUrB_lACLcBGAs/s1600/table.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. I know there are PHP JSON validators out there, here is a quick one I just rolled up.