if {{ name }}.is_null() {
        set_last_error(1, "Null pointer passed for parameter '{{ name }}'");
        {{ fail_ret }}
    }
    // SAFETY: null check above guarantees {{ name }} is a valid pointer; string is valid UTF-8 from caller.
    let {{ rs_name }}_str = match unsafe { CStr::from_ptr({{ name }}) }.to_str() {
        Ok(s) => s,
        Err(_) => {
            set_last_error(1, "Invalid UTF-8 in parameter '{{ name }}'");
            {{ fail_ret }}
        }
    };
    let {{ mut_keyword }}{{ rs_name }} = match serde_json::from_str{{ turbofish }}({{ rs_name }}_str) {
        Ok(v) => v,
        Err(e) => {
            set_last_error(2, &e.to_string());
            {{ fail_ret }}
        }
    };
