JS object conversion accepts functions returning objects and arrays