Questions tagged [ajv]

Ajv is a JSON schema validators for node.js and browser. It supports draft 4, 6, and 7, and additional extras beyond JSON Schema that make it more useful.

Ajv is a JSON Schema validator for Node.js and the browser. It supports draft 4, 6, and 7, and additional extras beyond JSON Schema that make it more useful.

Related tags:

375 questions
5
votes
0 answers

Is there any way to use AJV to load an schema from an external URL

Is there any way to load a json schema in AJV with URL. I was using this code to load a json schema from mockable.io. var ajv = new Ajv({ loadSchema: loadSchema }); ajv.compileAsync("http://demo3880044.mockable.io/").then(function (validate) { …
James Hameson
  • 331
  • 1
  • 4
  • 10
5
votes
1 answer

How to use JsonSchema for real-time client-side validation?

I'm evaluating using JSON Schema for validating form data. I can use it to validate my form data when you click submit using AJV and then check it again on the server using a PHP implementation of JSON Schema. That part sounds great, but I'm trying…
mpen
  • 272,448
  • 266
  • 850
  • 1,236
5
votes
1 answer

How to use definitions from external files in JSON Schema?

I'm trying to import the definitions from another json schema using $ref but getting the following error: can't resolve reference ../base/definitions.schema.json#/definitions/datetime from id # { "$schema":…
Sayem
  • 6,079
  • 4
  • 22
  • 26
5
votes
0 answers

AJV validation: inconsistent dataPath

I have an AJV schema like this: // schema.js module.exports = { title: 'task', description: 'A Task Schema', type: 'object', properties: { object_city: { title: 'City', type:'string' }, object_zip: { title: 'Zip…
LongHike
  • 4,016
  • 4
  • 37
  • 76
5
votes
1 answer

AJV schema validation for nested object

Functions returns object which looks something like this: { "answer": { "vehicle_type": 1, "message": "Car" }, "model": "VW", "color": "red" } 'Answer' object is always there. Other…
Klik Kliković
  • 364
  • 1
  • 5
  • 13
5
votes
1 answer

AJV custom keyword validation

I'm using AJV library to validate my JSON schema. I want to be able to validate Startdate to be a string. In the case where it is not a string, it should be converted to N/A. Currently, it only converts undefined to N/A. However, in these cases it…
eagercoder
  • 526
  • 1
  • 10
  • 23
5
votes
1 answer

Error: can't resolve reference error.json from id #

I not understand how correct reference to other schema. I used ajv, and have next two schema First schema incorrect-email.json: { "title": "Не корректный email", "properties": { "status": { "description": "Статус операции", …
Mihail Kuznetsov
  • 323
  • 5
  • 22
5
votes
1 answer

Why is Ajv unable to resolve reference during compile?

The following is an example of the JSON schema that I am trying to compile and use for validation. To accomplish this I am using the 'ajv' npm module. Here is the code that I am running ... var ajv = require('ajv')(); var contactSchema = { …
ra9r
  • 4,528
  • 4
  • 42
  • 52
4
votes
2 answers

How can I specify a maximum or minimum number with AJV for JSON Type Definition (JTD)?

How can I specify a maximum or minimum number with AJV for JSON Type Definition (JTD)? I don't see anywhere in the docs how to specify.
Ben Stickley
  • 1,551
  • 1
  • 16
  • 22
4
votes
1 answer

How to statically validate JS construction statement by statement

I have JS as defined below (JS File). On push to a repo I want to statically validate things defined below (Validate This). I've been researching this and my first idea is to validate items 1-4 using https://www.npmjs.com/package/espree. …
Captain Kirk
  • 350
  • 6
  • 24
4
votes
1 answer

Validate UTC date/date-time with ajv but allow empty strings

I need to validate string schema format: "date" or format: "date-time" to accept only ISO 8601 but also allow empty string "" (the "" requirement should be separately checked using the required schema). { "datetime1": { "type": "string", …
Andrew Ooi
  • 309
  • 1
  • 3
  • 10
4
votes
1 answer

AJV - Reference external schema without adding it first

Is it possible to use AJV to reference a schema that was previously not added through addSchema()? I want to resolve a reference like this: { "$schema": "http://json-schema.org/draft-07/schema", "type": "object", "additionalProperties":…
Lehks
  • 2,582
  • 4
  • 19
  • 50
4
votes
1 answer

Open API 3 - How to describe a query parameter that is an array of integers but can be a single item?

Using Open API 3.0.1, I'm trying to describe a query parameter of type "integer", lets say we call it ids, that can be alone or can be an array. For example: /my-endpoint?ids=111 or /my-endpoint?ids=111&ids=222 I did try: - name: ids in: query …
electrotype
  • 8,342
  • 11
  • 59
  • 96
4
votes
1 answer

Nesting oneOf in anyOf for a JSON Schema

Here is the JSON Schema and the JSON as provided below in the link for illustartion purpose. JSON Schema and the JSON Format: The Individual JSON object (with their additional attributes and may vary with other object in the array) within array can…
user8479984
  • 451
  • 2
  • 9
  • 23
4
votes
2 answers

JSON Schema Is it possible to use if/then/else which refer to outside property

I want to add conditionally required based on value of some other property. 'companyName' and 'companyAddress' should be required only if 'isInexperienced' value is false. Schema { "type": "object", "properties": { …
1 2
3
24 25