<div dir="ltr"><div>Is there a way to directly pass json data from a form, using request.get_json() into a wtform object at instantiation? <br><br>Basically what I want would be something like:<br><br>    validation_form = MyForm(json_form_data = request.get_json())<br></div><div>    validation_form.validate()<br></div><div>    ... do stuff depending on validation ...<br></div><div><br>Details: <br><br>I'm trying to get the data from a form to server-side in order to validate it with wtforms. (I pass the data via AJAX from a wtform inheriting the flask-wtf Form object.) <br><br>I am using $("#targetForm").serializeArray() and passing that as the data: attribute in the ajax call. I pass it to the server as "application/json" type and retrieve it in the Flask view function with request.get_json().<br><br></div><div>Thus far, I am able to validate the form with something like:<br><br><br>    validation_form = create_modal_form(item, for_validation = True,<br>                                                               csrf_token = form_data['csrf_token'],<br>                                                               sides = form_data['sides'])<br><br><br></div><div>Sparing some of the details, create_modal_form does basically this:<br><br><br>    def create_modal_form(item_object, prefix_string = '', for_validation = False, **kwargs):<br>        class ModalForm(Form):<br><br></div><div>        ... functionally declare a bunch of fields dependent upon item_object properties ...<br></div><div>        <br>        if not for_validation:<br>            return ModalForm(prefix=prefix_string)<br>        else:<br>            return ModalForm(formdata=None, **kwargs)<br><br><br></div><div>The important thing is that when I am looking to validate, I pass in the data to the wtform object instantiation as *kwargs. (Like csrf_token and sides in the call above and it works.)<br></div><div><br></div><div>Any advice and comments appreciated!<br></div><div> <br></div></div>