Runkit
Runkit
home page
user forum
new notebook
clone notebook
download notebook
support & documentation
log in
sign up
new notebook
help & feedback
clone this notebook
download this notebook
Sign In
Sign Up
RunKit + npm: ajv
node v8.17.0
endpoint
share
tweet
var Ajv = require('ajv'); var ajv = new Ajv({allErrors: true}); ajv.addKeyword('my_id_rewrite', { type: 'object', compile: function (sch, parentSchema) { return function (data) { console.log(data) data['my_id']=parentSchema.my_id_rewrite; return true; } } }); var schema = { "my_id_rewrite": 2 }; var validate = ajv.compile(schema); o = {"my_id":1} console.log(validate(o)); // true console.log(o); // Object {my_id: 2}
Created from: https://npm.runkit.com/ajv
Loading…
Clone and edit this document