forked from madjin/tweets2character
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate.mjs
More file actions
26 lines (20 loc) · 733 Bytes
/
Copy pathvalidate.mjs
File metadata and controls
26 lines (20 loc) · 733 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import fs from 'fs';
import Ajv from 'ajv';
// Read the JSON schema file
const schemaJson = fs.readFileSync('schema/character.schema.json', 'utf-8');
const schema = JSON.parse(schemaJson);
// Read the JSON file to validate
const jsonString = fs.readFileSync('examples/example.character.json', 'utf-8');
const jsonData = JSON.parse(jsonString);
// Create an Ajv instance
const ajv = new Ajv();
// Compile the schema
const validate = ajv.compile(schema);
// Validate the JSON data against the schema
const valid = validate(jsonData);
if (valid) {
console.log('JSON file is valid against the schema.');
} else {
console.log('JSON file is not valid against the schema.');
console.log('Validation errors:', validate.errors);
}