Its easy to load JSON into an object in javascript using eval or JSON.parse.
But if you have a proper \"class\" like function, how do you get the JSON data into it?<
Many frameworks provide an 'extend' function that will copy fields over from one object to another. You can combine this with JSON.parse to do what you want.
newPerson = new Person();
_.extend(newPerson, JSON.parse(aPersonJSON));
If you don't want to include something like underscore you can always copy over just the extend function or write your own.
Coffeescript example because I was bored:
JSONExtend = (obj, json) ->
obj[field] = value for own field, value of JSON.parse json
return obj
class Person
toString: -> "Hi I'm #{@name} and I'm #{@age} years old."
dude = JSONExtend new Person, '{"name":"bob", "age":27}'
console.log dude.toString()