<commit_before>import json

import cherrypy
from cherrypy._cperror import HTTPError, _be_ie_unfriendly, clean_headers
from schematics.datastructures import FrozenDict
from schematics.exceptions import DataError


def json_errors_to_json(validation_errors, root=None):
    json_errors = []
    for key, value in validation_errors.items():
        if isinstance(value, dict):
            json_errors.extend(json_errors_to_json(value, root=key))
        else:
            if isinstance(value, str):
                json_errors.append({
                    'detail': value,
                    'source': {
                        'pointer': root + "/" + key
                    }
                })
            elif isinstance(value, FrozenDict):
                for k in value.keys():
                    for field in value[k].keys():
                        json_errors.extend(json_errors_to_json({str(k): value[k][field]}, root=root + "/" + key))
            else:
                for error in value:
                    json_errors.append({
                        'detail': error.summary,<commit_msg>Fix validation error with nested documents<commit_after>import json

import cherrypy
from cherrypy._cperror import HTTPError, _be_ie_unfriendly, clean_headers
from schematics.datastructures import FrozenDict
from schematics.exceptions import DataError


def json_errors_to_json(validation_errors, root=None):
    json_errors = []
    for key, value in validation_errors.items():
        if isinstance(value, dict):
            json_errors.extend(json_errors_to_json(value, root=key))
        else:
            if isinstance(value, str):
                json_errors.append({
                    'detail': value,
                    'source': {
                        'pointer': root + "/" + key
                    }
                })
            elif isinstance(value, FrozenDict):
                for k in value.keys():
                    if isinstance(value[k], dict):
                        for field in value[k].keys():
                            json_errors.extend(json_errors_to_json({str(k): value[k][field]}, root=root + "/" + key))
                    else:
                        json_errors.extend(json_errors_to_json({str(k): value[k]}, root=root+"/"+key))
            else:
                for error in value:
                    json_errors.append({
                        'detail': error.summary,
{'fraction_non_alphanumeric': 0.09673418768085985, 'fraction_numerical': 0.0, 'mean_word_length': 1.7282976324689967, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2632864', 'n_tokens_mistral': 645, 'n_tokens_neox': 614, 'n_words': 143}