> ## Documentation Index
> Fetch the complete documentation index at: https://intunedhq.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# validateDataUsingSchema

Validates data against a JSON schema using the AJV validator.
This function can validate any given data against a given schema. It supports validating custom data types such as the [Attachment](https://intunedhq.com/docs/automation-sdks/intuned-sdk/typescript/helpers/type-references/Attachment.md) type.

```typescript theme={null}
export declare function validateDataUsingSchema(input: {
  data: Record<string, any>[] | Record<string, any>;
  schema: Record<string, any>;
}): void;
```

## Examples

```typescript Basic Validation theme={null}
import { validateDataUsingSchema } from "@intuned/browser";
import { BrowserContext, Page } from "playwright";

interface Params {}

export default async function handler(
  params: Params,
  page: Page,
  context: BrowserContext
) {
  const uploadData = {
    file: {
      fileName: "documents/report.pdf",
      bucket: "my-bucket",
      region: "us-east-1",
      key: "documents/report.pdf",
      endpoint: null,
      suggestedFileName: "Monthly Report.pdf",
      fileType: "document",
    },
    name: "Test File Upload",
  };

  const uploadSchema = {
    type: "object",
    required: ["file", "name"],
    properties: {
      file: { type: "attachment" },
      name: { type: "string" },
    },
  };

  validateDataUsingSchema({ data: uploadData, schema: uploadSchema });
  // Validation passes with Attachment type
  console.log("Validation passed");
  return "Validation passed";
}
```

```typescript Invalid Data Validation theme={null}
import { validateDataUsingSchema } from "@intuned/browser";
import { BrowserContext, Page } from "playwright";

interface Params {}

export default async function handler(
  params: Params,
  page: Page,
  context: BrowserContext
) {
  const userData = {
    name: "John Doe",
    email: "john@example.com",
  };

  const userSchema = {
    type: "object",
    required: ["name", "email", "age"],
    properties: {
      name: { type: "string", minLength: 1 },
      email: { type: "string", format: "email" },
      age: { type: "number", minimum: 0 },
    },
  };

  validateDataUsingSchema({ data: userData, schema: userSchema }); // this will throw
  // Validation fails, throws ValidationError
  console.log("Never reached");
  return "Never reached";
}
```

## Arguments

**input** `Object` *required*

The input object containing data and schema

**properties**

**input.data** `Record\<string, any\> | Array\<Record\<string, any\>\>` *required*

The data to validate. Can be a single data object or an array of data objects

**input.schema** `Record\<string, any\>` *required*

JSON schema object defining validation rules

## Returns: `void`

Returns nothing if validation passes, throws ValidationError if it fails

## Raises

### ValidationError

If validation fails


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.