假设我有架构和 JSON:
JSON 架构:
const schema = {
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"required": [ "countries" ],
"definitions": {
"europeDef": {
"type": "object",
"required": ["type"],
"properties": { "type": {"const": "europe"} }
},
"asiaDef": {
"type": "object",
"required": ["type"],
"properties": { "type": {"const": "asia"} }
}
},
"properties": {
"countries": {
"type": "array",
"items": {
"oneOf":[
{ "$ref": "#/definitions/europeDef" },
{ "$ref": "#/definitions/asiaDef"}
]
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
JSON:
const data = {
"countries":[
{"type": "asia1"},
{"type": "europe1"}
]
}
Run Code Online (Sandbox Code Playgroud)
const isValid …Run Code Online (Sandbox Code Playgroud) 以下是一些包含单引号的文本:
Cannot read property 'email' of undefined:
Run Code Online (Sandbox Code Playgroud)
当我使用上述文本运行以下查询时
filter @message like /Cannot read property 'email' of undefined/
| stats count()
Run Code Online (Sandbox Code Playgroud)
我无法计数。然而,实际上我的日志中有很多上面的文字。
问题是,如何转义查询中的单引号?
以下是 JSON 架构和下面链接中提供的 JSON,用于说明目的。
格式:数组中的单个 JSON 对象(及其附加属性,可能会因数组中的其他对象而异)可以属于任意 3 个区域:“美洲”、“亚洲”和“欧洲”,并且至少在区域类型上对象应该在那里。这可以通过数组 minItems 属性来实现)
问题陈述:
数组中的单个 JSON 对象可以属于任意 3 个区域:“美国”、“亚洲”和“欧洲”,并且至少应该存在区域对象的类型
==> 我可以通过将所有区域对象放入 anyOf 数组中来解决此问题,因为我想匹配至少一个有效区域对象。
JSON 对象“亚洲”或“欧洲”可以与其他区域类型一起存在。两者不能共存。
==> 我尝试使用“oneOf”,但它通过了 ajv 验证。其实应该会失败。任何人都可以帮忙。谢谢
JSON 模式
{
"type": "object",
"properties": {
"stat_data": {
"type": "array",
"minItems": 1,
"items": {
"type": "object",
"properties": {},
"anyOf": [{
"required": ["region"],
"properties": {
"region": {
"enum": ["america"]
},
"country": {
"type": "string"
},
"population": {
"type": "string"
}
}
},
{
"oneOf": [
{
"required": ["region"],
"properties": { …Run Code Online (Sandbox Code Playgroud)