Construct var programmatically and convert to JSON

I created this function to help solve this problem.  

void varSetProperty(var& object, String key, var value){

    if (object.isObject()

        object.getDynamicObject()->setProperty(key, value);

}

void someCode(){

var myJSONObject(new DynamicObject());

varSetProperty(myJSONObject, "name", "Jules");

}

Using object vars this way I can create any kind of JSON data programmatically.

Unless I am being dumb and missing something, it seems to me that the var class is missing a setProperty type of method like this.