question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AJV taking too long for compile schema

See original GitHub issue

Hi, i am using ajv for validate huge jsons.

I’m parsing 1000 lines to json and sending to ajv.compile but is taking about 30,40 secons to compile, it is normal take too long?

I used to had this working fine, but since last weekend the compile is almost impossible to use. I’ll post my method of validation , if it is something wrong please tell me, i dont know what to do anymore. `export function validateSchema( arrayJson: Array<iSchema>, schema: any, file: Files, maxErrors: number, numErrors: number, callback: Function ) { Arrayerror = []; let teste = 0; try { for (var values of arrayJson) { if (numErrors >= maxErrors) { break; } const ajvTeste = new Ajv({ strict: false, allErrors: true, }); require(“ajv-keywords”)(ajvTeste); addFormats(ajvTeste); AjvErrors(ajvTeste);

  let validate2 = ajvTeste.compile(schema);

  if (validate2(values)) {
    teste++;
  } else {
    ErrorFields =
      validate2.errors &&
      validate2.errors?.map((vals) => {
        return vals.dataPath;
      });
  }

  if (ajvTeste.errorsText(validate2.errors) !== "No errors") {
    numErrors++;
    Arrayerror.push({
      line: values.seq,
      errors: ajvTeste.errorsText(validate2.errors).split(","),
      campo: Array.prototype.join.call(ErrorFields).split(","),
      file: file,
      layout: values.tabela,
      full_line_error: values.linha,
    });
  }
}
return callback(Arrayerror, numErrors);

} catch (e) { console.log(“w”); } }`

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
pedro-dardecommented, Jun 8, 2021

For shure, thanks for help, it really helped me in this case 😃

0reactions
epoberezkincommented, Jan 15, 2022

This depends on which frameworks you use and how your application is structured, Ajv doesn’t prescribe any specific steps other than API it exposes.

There are some recipes here: https://ajv.js.org/guide/managing-schemas.html

Read more comments on GitHub >

github_iconTop Results From Across the Web

Managing schemas - Ajv JSON schema validator
Managing schemas. Re-using validation functions; Standalone validation code; Compiling during initialization; Using Ajv instance cache.
Read more >
How to fix ajv schema not being checked correctly while ...
Basically I am currently writing a unit test for a function which checks if a json -file is valid, using an AJV Schema....
Read more >
Ajv JSON schema validator - npm
Start using ajv in your project by running `npm i ajv`. ... Ajv generates code to turn JSON Schemas into super-fast validation functions ......
Read more >
Ajv: Another JSON Schema Validator - GitLab
I am looking for the long term maintainers of Ajv – working with ReadySet, ... If you're using Ajv to compile a schema...
Read more >
Ajv JSON schema validation - YouTube
introduction to Ajv JSON schema validation ... We talk about how to set up Ajv with express and we create a custom Ajv...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found