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
3
votes
1 answer

AJV - How to add custom Error messages in Javascrip

I am using AJV for custom validation. I want to change the error message as well while validate, I am using - var imageValidation = { required: ['name',…
Atique Ahmed
  • 308
  • 4
  • 16
3
votes
1 answer

AJV validator and custom or user-friendly error message

I have the following schema and json to validate using ajv. I am developing a REST API that takes a JSON and gets validated against the schema and it returns the error (400- with the ajv error) or (200 - when successfully validated) const schema =…
user8479984
  • 451
  • 2
  • 9
  • 23
3
votes
1 answer

How to validate data based on an input value with AJV?

I am using AJV trying to validate some data and dynamically require properties based on another property's value. What I am trying to validate is: - enabled is always required, - if enabled = true then only one of the other properties (realtime,…
Stefan
  • 1,214
  • 1
  • 9
  • 17
3
votes
4 answers

AJV schema validation for object with unknown properties

I have a funny scenario all over my platform, but I believe it's the best. I am trying to validate a JSON Schema where an object has unknown keys with the same schema as value. The keys are unique ID's and the value of those keys have the same…
Carlino Gonzalez
  • 189
  • 1
  • 11
3
votes
1 answer

Check JSON Schema which is syntactically correct, but not semantically

I want to check the JSON schema itself which is syntactically correct, but not semantically . e.g { "$schema": "http://json-schema.org/draft-07/schema#", "$id": "http://example.com/root.json", "type": "object", "required": [ …
eagle
  • 312
  • 1
  • 13
3
votes
2 answers

AJV's validator returns always true value

I need to validate JSON files in following way: const setupSchema = fs.readFileSync(schemaDir +'/setup.json'); and compiling: const setupValidator = ajv.compile(setupSchema); My issue is that line: console.log( setupValidator('') ); Always…
Tomasz Waszczyk
  • 2,680
  • 5
  • 35
  • 73
3
votes
1 answer

NodeJS Ajv module alway log message ' $ref: keywords ignored in schema at path "#" '

I'm using ajv to validate body request. With each one request come, ajv working is ok but it always log message ' $ref: keywords ignored in schema at path "#" ' I have 2 schemas, login.json & login.defs.json login.defs.json to define a common schema…
Vũ Anh Dũng
  • 980
  • 3
  • 13
  • 32
3
votes
2 answers

How do I declare dependencies of nested properties?

I am using Draft-04 of JSON Schema. Is it possible to set dependencies based on the existence of a sub-property, and/or depend on a sub-property? Or am I forced to use allOf to manage these kinds of dependencies? I have the following (you can play…
neverendingqs
  • 4,006
  • 3
  • 29
  • 57
3
votes
3 answers

AJV schema validation fails

I am using Jsonix, I have used below mentioned command to generate jsonix mapping and jsonix schema as, java -jar jsonix-schema-compiler-full.jar -generateJsonSchema -d mappings books.xsd it is properly generating mapping and schema, I want to…
J1617
  • 91
  • 1
  • 10
3
votes
3 answers

JSON Schema extract the required fields

I need to get a list of the required fields out of a JSON-Schema+Data. Currently, we are using AJV to get error messages in our forms with JSON Schema and it is working great. I need a way to get all the required fields (even if filled) in order to…
Mike
  • 741
  • 13
  • 40
3
votes
2 answers

Validating Request Schema With Fastify and AJV

Background I'm building an API with Fastify and it's my first time using JSON schema validation. The idea is that it will both make the server code more efficient and help our developers as they learn how to consume my API. Problem I'm trying to…
Mike Fleming
  • 2,593
  • 4
  • 14
  • 24
3
votes
1 answer

Getting error type/value when validating json schema with ajv

I'm trying to use json schema to validate the json of an api. I've found the ajv library, which seems to be the most popular for node.js. Just getting the basics, I've defined my schema as const viewSchema = { "type": "object", …
pedalpete
  • 21,076
  • 45
  • 128
  • 239
3
votes
2 answers

AJV: check if a property equals another property

By using ajv, how can I reference foo to validate that bar has the same value? var Ajv = require('ajv'); var ajv = new Ajv({allErrors: true}); var schema = { 'properties': { 'foo': { 'type': 'string', 'minLength': 3 }, 'bar': { 'type':…
DKo
  • 820
  • 1
  • 9
  • 19
3
votes
1 answer

JSON schema validate oneOf two or allOf

i want to validate following json schema, i am using Ajv npm package. { "email": "xyzmail@gmail.com", "phone": "1112223334", "country_code": "91" } i want either email only, or phone and country_code only, or all of three properties…
Vinay Pandya
  • 3,020
  • 2
  • 26
  • 42
2
votes
1 answer

Error TS2351: This expression is not constructable. (AJV with TypeScript)

this is more of an issue I am facing using AJV with Typescript. I raised an similar issue in the ajv repo but couldn't really find an solution. I am trying to import the Ajv module from ajv as such: import Ajv from "ajv; And, use it as I used to do…