使用AJV在JSON模式中验证空值 [英] Empty values validation in json schema using AJV

查看:146
本文介绍了使用AJV在JSON模式中验证空值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Ajv验证我的JSON数据.我无法找到一种方法来验证空字符串作为键的值.我尝试使用模式,但没有引发适当的消息.

I am using Ajv for validating my JSON data. I am unable to find a way to validate empty string as a value of a key. I tried using pattern, but it does not throw appropriate message.

这是我的架构

{
    "type": "object",
    "properties": {
        "user_name": { "type": "string" , "minLength": 1},
        "user_email": { "type": "string" , "minLength": 1},
        "user_contact": { "type": "string" , "minLength": 1}
    },
    "required": [ "user_name", 'user_email', 'user_contact']
}

我正在使用minLength来检查该值应包含至少一个字符.但它也允许有空白空间.

I am using minLength to check that value should contain at least one character. But it also allows empty space.

推荐答案

目前,AJV中没有内置选项可以做到这一点.

Right now there is no built in option in AJV to do so.

这篇关于使用AJV在JSON模式中验证空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆