function checkValidation(propertyMetadata, jsonData) {
  // filters invalid fields
  const result = propertyMetadata.filter((obj) => {
    // check only fields to validate
    if (obj.hasOwnProperty('validate')) {
      const value = jsonData[obj.propertyName];
      if (Array.isArray(value)) {
        // returns true or false for all item in array.
        const isValid = value.every((string) => {
          return checkStringForPattern(string, obj.validate);
        });
        if (!isValid) {
          return obj;
        }
      } else { // check string
        const isValid = checkStringForPattern(value, obj.validate);
        if (!isValid) {
          return obj;
        }
      }
    }
  }).reduce((accumulatorObj, propertyMetadataObj) => {
    const name = propertyMetadataObj.propertyName;
    accumulatorObj[name] = jsonData[name];
    return accumulatorObj;
  }, {});

  // if all fields are valid, result is an empty array.
  // return an empty obj instead
  return Array.isArray(result) ? {} : result;
}
/**
 * @param {Array} propertyMetadata Contains data validation
 * @param {Object} jsonData JSON object with all postable data from form
 * @returns {Object} With keys as propertyName of invalid fields,
 * or empty object if all fields are valid
*/
@param {Array} propertyMetadata Contains data validation
@param {Object} jsonData JSON object with all postable data from form
@returns {Object} With keys as propertyName of invalid fields,
or empty object if all fields are valid
@param { Array } propertyMetadata Contains data validation @param { Object } jsonData JSON object with all postable data from form @returns { Object } With keys as propertyName of invalid fields or empty object if all fields are valid
function checkValidation(propertyMetadata, jsonData) {
  const result = propertyMetadata.filter((obj) => {
    if (obj.hasOwnProperty('validate')) {
      const value = jsonData[obj.propertyName];
      if (Array.isArray(value)) {
        const isValid = value.every((string) => {
          return checkStringForPattern(string, obj.validate);
        });
        if (!isValid) {
          return obj;
        }
      } else { 
        const isValid = checkStringForPattern(value, obj.validate);
        if (!isValid) {
          return obj;
        }
      }
    }
  }).reduce((accumulatorObj, propertyMetadataObj) => {
    const name = propertyMetadataObj.propertyName;
    accumulatorObj[name] = jsonData[name];
    return accumulatorObj;
  }, {});
  return Array.isArray(result) ? {} : result;
}
function checkValidation ( propertyMetadata , jsonData ) { const result = propertyMetadata . filter ( ( obj ) => { if ( obj . hasOwnProperty ( 'validate' ) ) { const value = jsonData [ obj . propertyName ] ; if ( Array . isArray ( value ) ) { const isValid = value . every ( ( string ) => { return checkStringForPattern ( string , obj . validate ) ; } ) ; if ( ! isValid ) { return obj ; } } else { const isValid = checkStringForPattern ( value , obj . validate ) ; if ( ! isValid ) { return obj ; } } } } ) . reduce ( ( accumulatorObj , propertyMetadataObj ) => { const name = propertyMetadataObj . propertyName ; accumulatorObj [ name ] = jsonData [ name ] ; return accumulatorObj ; } , { } ) ; return Array . isArray ( result ) ? { } : result ; }
@param {Array} propertyMetadata Contains data validation
 @param {Object} jsonData JSON object with all postable data from form
 @returns {Object} With keys as propertyName of invalid fields,
 or empty object if all fields are valid
@param { Array } propertyMetadata Contains data validation @param { Object } jsonData JSON object with all postable data from form @returns { Object } With keys as propertyName of invalid fields or empty object if all fields are valid
// filters invalid fields // check only fields to validate // returns true or false for all item in array. // check string // if all fields are valid, result is an empty array. // return an empty obj instead