Instantiate an stdClass object from json schema specification in PHP -


i have set of json requests must send restful api in order response objects, know, usual thing webapp, these api request objects documented json schema specification each, load schema files , create stdclass object instances based on info automagically.

is there way library or in php? (don't want reinvent wheel)

thanks!

edit: have @ this schema file contains example of want load , build object instances from.

disclaimer: know json_encode / json_decode not i'm looking for. using i'd need traverse through returned schema object , create object/array based on schema read, not want.

i don't think there's built-in way of doing this, should relatively trivial implement:

function createobj( $json ) {     $obj_schema = json_decode($json, true);     $new_obj = new stdclass;     foreach($obj_schema['properties'] $property) {       $new_obj->{$property} = null;     }      return $new_obj; } 

Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -