A json factory in javascript