def json_validate(self, data, piecewise=False, raw=False):
        """ The same as :meth:`Form.validate_render` except the errors
        are loaded into a JSON string to be passed back as a query
        result. This output is designed to be used by the Yota
        Javascript library.

        :param piecewise: If set to True, the validator will silently
            ignore validator for which it has insufficient information. This
            is designed to be used for the AJAJ piecewise validation
            function, although it does not have to be.
        :type piecewise: boolean

        :param raw: If set to True then the second return parameter will be a
            Python dictionary instead of a JSON string
        :type raw: boolean

        :return: A boolean whether or not the form submission is valid and the
            json string (or raw dictionary) to pass back to the javascript side.
            The boolean is an anding of submission (whether the submit button was
            actually pressed) and the block parameter (whether or not any blocking
            validators passed)
        """

        # Allows user to set a modular processor on incoming data
        data = self._processor().filter_post(data)

        errors = {}
        """ We want to automatically block the form from actually submitting
        if this is piecewise validation. In addition if they are actually
        submitting then we want to run it as non-piecewise validation """
        if data.get('submit_action', 'false') != 'true' and piecewise:
            block, invalid = self._gen_validate(data, piecewise=piecewise)
            block = True
        else:
            block, invalid = self._gen_validate(data, piecewise=False)

        # loop over our nodes and insert information for the JS callbacks
        for node in invalid:
            errors[node._attr_name] = {'identifiers': node.json_identifiers(),
                                       'errors': node.errors}

        # if needed we should run our all form message generator and return
        # json encoded error message
        retval = {'block': block}
        if len(errors) > 0:
            header_err = self.error_header_generate(errors, block)
            if header_err:
                errors['start'] = {'identifiers': self.start.json_identifiers(),
                                   'errors': header_err}

        if not block:
            blob = self.success_header_generate()
            if blob:
                retval['success_blob'] = blob
            if hasattr(self, 'start'):
                retval['success_ids'] = self.start.json_identifiers()

        retval['errors'] = errors

        # Throw back a variable in the json if there is both a submit
        # and no blocking errors. The main purpose here is the allow
        # easy catching of success in the view code.
        if data.get('submit_action', 'false') == 'true' and not block:
            valid = True
            self.trigger_event("validate_success")
        else:
            self.trigger_event("validate_failure")
            valid = False

        # Hold our return dictionary in memeory for easy editing later
        self._last_raw_json = retval

        # process the errors before we serialize
        self._process_errors()

        # Return our raw dictionary if requested, otherwise serialize for
        # convenience...
        if raw:
            return valid, retval
        else:
            return valid, json.dumps(retval)
dataset/ETHPy150Open icook/yota/src/yota/__init__.py/Form.json_validate/original