packages/optimizely-sdk/lib/utils/json_schema_validator/index.js
function(jsonSchema, jsonObject) {
    if (!jsonSchema) {
      throw new Error(sprintf(ERROR_MESSAGES.JSON_SCHEMA_EXPECTED, MODULE_NAME));
    }

    if (!jsonObject) {
      throw new Error(sprintf(ERROR_MESSAGES.NO_JSON_PROVIDED, MODULE_NAME));
    }

    var result = validate(jsonObject, jsonSchema);
    if (result.valid) {
      return true;
    } else {
      if (fns.isArray(result.errors)) {
        throw new Error(sprintf(ERROR_MESSAGES.INVALID_DATAFILE, MODULE_NAME, result.errors[0].property, result.errors[0].message));
      }
      throw new Error(sprintf(ERROR_MESSAGES.INVALID_JSON, MODULE_NAME));
    }
  }
function(jsonSchema, jsonObject) {
    if (!jsonSchema) {
      throw new Error(sprintf(ERROR_MESSAGES.JSON_SCHEMA_EXPECTED, MODULE_NAME));
    }

    if (!jsonObject) {
      throw new Error(sprintf(ERROR_MESSAGES.NO_JSON_PROVIDED, MODULE_NAME));
    }

    var result = validate(jsonObject, jsonSchema);
    if (result.valid) {
      return true;
    } else {
      if (fns.isArray(result.errors)) {
        throw new Error(sprintf(ERROR_MESSAGES.INVALID_DATAFILE, MODULE_NAME, result.errors[0].property, result.errors[0].message));
      }
      throw new Error(sprintf(ERROR_MESSAGES.INVALID_JSON, MODULE_NAME));
    }
  }
function ( jsonSchema , jsonObject ) { if ( ! jsonSchema ) { throw new Error ( sprintf ( ERROR_MESSAGES . JSON_SCHEMA_EXPECTED , MODULE_NAME ) ) ; } if ( ! jsonObject ) { throw new Error ( sprintf ( ERROR_MESSAGES . NO_JSON_PROVIDED , MODULE_NAME ) ) ; } var result = validate ( jsonObject , jsonSchema ) ; if ( result . valid ) { return true ; } else { if ( fns . isArray ( result . errors ) ) { throw new Error ( sprintf ( ERROR_MESSAGES . INVALID_DATAFILE , MODULE_NAME , result . errors [ 0 ] . property , result . errors [ 0 ] . message ) ) ; } throw new Error ( sprintf ( ERROR_MESSAGES . INVALID_JSON , MODULE_NAME ) ) ; } }
Validate the given json object against the specified schema
@param  {Object} jsonSchema The json schema to validate against
@param  {Object} jsonObject The object to validate against the schema
@return {Boolean}           True if the given object is valid
Validate the given json object against the specified schema