У меня есть JSON из-за ошибки Mongoose в приложении NodeJS с экспресс-фреймворком:
{
"err": {
"errors": {
"last_name": {
"message": "Path `last_name` is required.",
"name": "ValidatorError",
"properties": {
"message": "Path `last_name` is required.",
"type": "required",
"path": "last_name"
},
"kind": "required",
"path": "last_name"
},
"first_name": {
"message": "Path `first_name` is required.",
"name": "ValidatorError",
"properties": {
"message": "Path `first_name` is required.",
"type": "required",
"path": "first_name"
},
"kind": "required",
"path": "first_name"
},
"password": {
"message": "Path `password` (`iam`) is shorter than the minimum allowed length (6).",
"name": "ValidatorError",
"properties": {
"message": "Path `password` (`iam`) is shorter than the minimum allowed length (6).",
"type": "minlength",
"minlength": 6,
"path": "password",
"value": "iam"
},
"kind": "minlength",
"path": "password",
"value": "iam"
}
},
"_message": "User validation failed",
"message": "User validation failed: last_name: Path `last_name` is required., first_name: Path `first_name` is required., password: Path `password` (`iam`) is shorter than the minimum allowed length (6).",
"name": "ValidationError"
}
}
Как получить type
иpath
каждой ошибки внутри properties
, я пробовал forEach()
метод, но он не работал, есть ли другой способ перебрать этот JSON?