jquery populate form fields from json code example

Example: jquery populate form json

//Plugin  
(function($){
    $.fn.setFormData = function(data){
        let t = this;
        $.each(data, function(key, value) {  
            var ctrl = $(t).find('[name='+key+']');  
            switch(ctrl.prop("type")) { 
                case "radio": case "checkbox": case "select":   
                    ctrl.each(function() {
                        if($(this).attr('value') == value) $(this).attr("checked",value);
                    });   
                    break; 
                    case "select" :
                    // manipulate select?
                    ctrl.val(value); 
                    break;
                default:
                    ctrl.val(value); 
            }  
        });  
    }
  })(jQuery);

//Call
$('#form').setFormData(someData);