You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure Logic Apps JSON Schema验证:如何校验空字符串及邮箱格式?

Azure Logic Apps 复杂JSON验证解决方案

空字符串验证修正

Azure Logic Apps的Parse JSON活动对空字符串的处理和标准JSON Schema存在差异,单独配置minLength:1无法拦截空字符串。要解决这个问题,可在字段的Schema中同时添加"not": {"const": ""}来明确排除空字符串;若还需禁止纯空白字符组成的字符串,再补充"pattern": "^\\s*\\S.*$"。示例配置:

"FirstName": {
    "type": "string",
    "minLength": 1,
    "not": {
        "const": ""
    },
    "pattern": "^\\s*\\S.*$"
}

正则表达式配置修正

你提到的正则表达式不被支持,大概率是Schema整体结构有误,而非正则语法问题。确保正则字段嵌套在正确的properties结构中,JSON里的正则无需额外转义(除非包含反斜杠)。正确的示例配置:

"FirstName": {
    "type": "string",
    "minLength": 1,
    "pattern": "^.*[a-zA-Z0-9]+.*$"
}

邮箱格式验证

直接使用JSON Schema标准的format: "email"即可实现邮箱格式验证,Logic Apps的Parse JSON活动原生支持该格式,结合minLength:1可同时拦截空字符串:

"Email": {
    "type": "string",
    "format": "email",
    "minLength": 1
}

完整验证Schema示例

将上述规则整合后的完整Schema如下,配置后Parse JSON活动会自动执行所有验证,错误信息可通过outputs('Parse_JSON')?['Errors']直接获取,无需创建自定义条件活动:

{
    "type": "object",
    "properties": {
        "FirstName": {
            "type": "string",
            "minLength": 1,
            "not": {"const": ""},
            "pattern": "^\\s*\\S.*$"
        },
        "Email": {
            "type": "string",
            "format": "email",
            "minLength": 1
        }
    },
    "required": ["FirstName", "Email"]
}

内容的提问来源于stack exchange,提问作者puri

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.24 04:23:16