File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -166,6 +166,30 @@ console.log(validate.errors)
166
166
// [ { keywordLocation: '#/properties/hello/type', instanceLocation: '#/hello' } ]
167
167
```
168
168
169
+ Or, similarly, with parser API:
170
+
171
+ ``` js
172
+ const schema = {
173
+ $schema: ' https://json-schema.org/draft/2019-09/schema' ,
174
+ type: ' object' ,
175
+ required: [' hello' ],
176
+ properties: {
177
+ hello: {
178
+ type: ' string' ,
179
+ pattern: ' ^[a-z]+$' ,
180
+ }
181
+ },
182
+ additionalProperties: false ,
183
+ }
184
+ const parse = parser (schema, { includeErrors: true })
185
+
186
+ console .log (parse (' { "hello": 100 }' ));
187
+ // { valid: false,
188
+ // error: 'JSON validation failed for type at #/hello',
189
+ // errors: [ { keywordLocation: '#/properties/hello/type', instanceLocation: '#/hello' } ]
190
+ // }
191
+ ```
192
+
169
193
Only the first error is reported by default unless ` allErrors ` option is also set to ` true ` in
170
194
addition to ` includeErrors ` .
171
195
You can’t perform that action at this time.
0 commit comments