Skip to content

Instantly share code, notes, and snippets.

@wiky
Created July 25, 2012 18:53
Show Gist options
  • Save wiky/3177866 to your computer and use it in GitHub Desktop.
Save wiky/3177866 to your computer and use it in GitHub Desktop.
json api

#api

##JSON Reference

var family = {
	father: {
		name: 'Jim',
		son: {
			'$ref': '$.son'
		},
		wife: {
			'$ref': '$.mother'
		}
	},
	son: {
		name: 'Sim',
		father: {
			'$ref': '$.father'
		}
	},
	mother: {
		name: 'lin',
		husband: {
			'$ref': '$.father'
		}
	}
};

equals

var family = {
	father: {
		name: 'Jim'
	},
	son: {
		name: 'Sim'
	},
	mother: {
		name: 'lin'
	}
};
family.father.son = family.son;
family.father.wife = family.wife;
family.son.father = family.father;
family.wife.husband = family.father;

##JSON Schema

{
	'description': 'A person',
	'type': 'object',
	'properties': {
		'name': {
			'type': 'string'
		},
		'gender': {
			'type': 'string',
			'enum': ['male', 'female']
		}
	},
	'additionalProperties': false
}

instance:

{
	'name': 'wiky',
	'gender': 'male'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment