How to use the is-my-json-valid.filter function in is-my-json-valid

To help you get started, we’ve selected a few is-my-json-valid examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Automattic / wp-calypso / client / lib / make-json-schema-parser / index.js View on Github external
const genParser = () => {
		const options = Object.assign( { greedy: true, verbose: true }, schemaOptions );
		const validator = schemaValidator( schema, options );

		// filter out unwanted properties even though we may have let them slip past validation
		// note: this property does not nest deeply into the data structure, that is, properties
		// of a property that aren't in the schema could still come through since only the top
		// level of properties are pruned
		const filter = schemaValidator.filter(
			Object.assign(
				{},
				schema,
				schema.type && schema.type === 'object' && { additionalProperties: false }
			)
		);

		validate = data => {
			if ( ! validator( data ) ) {
				if ( 'development' === process.env.NODE_ENV ) {
					// eslint-disable-next-line no-console
					console.warn( 'JSON Validation Failure' );

					validator.errors.forEach( error =>
						// eslint-disable-next-line no-console
						console.warn( {
github voronianski / is-my-schema-valid / src / is-my-schema-valid.js View on Github external
function validate (data, schema = {}, options = {}) {
    const schemaObj = schema.type ? schema : Object.assign({}, schemaPattern, {properties: schema});
    const formats = options.formats ? Object.assign({}, customFormats, options.formats) : customFormats;
    const validator = createValidator(schemaObj, { formats });

    if (options.filter) {
        const filter = createValidator.filter(schemaObj);
        data = filter(data);
    }

    const validatedData = validator(data);
    if (!validatedData) {
        return {
            valid: false,
            errors: _parseValidatorErrors(validator.errors, {
                title: schema.title,
                debug: options.debug
            })
        };
    }

    if (validatedData && options.filterReadonly) {
        const readonlyProperties = traverse(schemaObj).reduce(function (memo, value) {
github Automattic / wp-calypso / client / __mocks__ / is-my-json-valid.js View on Github external
validator.filter = ( schema, options ) => {
	throwOnInvalidSchema( schema );
	return imjv.filter( schema, options );
};

is-my-json-valid

A [JSONSchema](https://json-schema.org/) validator that uses code generation to be extremely fast.

MIT
Latest version published 2 years ago

Package Health Score

71 / 100
Full package analysis