let obj = { "city" : "chicago", "number": 20, "user" : { "name":"Alex", "age":20 } } console.log(jsonschema(obj)) function jsonschema(obj){ let res = {}; res['type'] = typeof obj; if( typeof obj == 'object'){ res['properties'] = {} for(let item in obj){ res['properties'][item] = jsonschema(item) } } return res }