> For the complete documentation index, see [llms.txt](https://docs.pyck.cloud/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.pyck.cloud/graphql-api/mutations/generatejsonschema.md).

# Generate JSON Schema

generateJsonSchema Mutation

Generates a JSON Schema definition from provided JSON data. This utility mutation helps create standardized schema definitions for dynamic data structures in the pyck system.

## Arguments

| Name       | Type      | Description                                            |
| ---------- | --------- | ------------------------------------------------------ |
| `jsonData` | `String!` | Required JSON string from which to generate the schema |

## Return Type

`GenerateJsonSchemaResponse!` - Contains the generated JSON Schema.

## Response Fields

`GenerateJsonSchemaResponse`:

| Field        | Type      | Description                           |
| ------------ | --------- | ------------------------------------- |
| `jsonSchema` | `String!` | The generated JSON Schema as a string |

## Usage Example

```graphql
mutation {
  generateJsonSchema(
    jsonData: "{\"name\": \"John Doe\", \"age\": 30, \"email\": \"john@example.com\", \"active\": true}"
  ) {
    jsonSchema
  }
}
```

## JavaScript Example

```javascript
const generateJsonSchemaMutation = `
  mutation GenerateJsonSchema($jsonData: String!) {
    generateJsonSchema(jsonData: $jsonData) {
      jsonSchema
    }
  }
`;

const sampleData = {
  name: "John Doe",
  age: 30,
  email: "john@example.com",
  active: true,
  preferences: {
    theme: "dark",
    notifications: true
  },
  tags: ["customer", "premium"]
};

const variables = {
  jsonData: JSON.stringify(sampleData)
};

// Using fetch or your preferred GraphQL client
const response = await fetch('/graphql', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    query: generateJsonSchemaMutation,
    variables: variables
  })
});

const result = await response.json();
const generatedSchema = JSON.parse(result.data.generateJsonSchema.jsonSchema);
console.log('Generated JSON Schema:', generatedSchema);
```

## Expected Response

The generated JSON Schema will follow the JSON Schema specification and might look like:

```json
{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "name": {
      "type": "string"
    },
    "age": {
      "type": "integer"
    },
    "email": {
      "type": "string"
    },
    "active": {
      "type": "boolean"
    }
  },
  "required": ["name", "age", "email", "active"]
}
```

## Notes

* The input must be valid JSON string format
* The generated schema follows JSON Schema Draft 7 specification
* Complex nested objects and arrays are supported
* The schema can be used for validation in data type definitions
* This is useful for creating dynamic data validation rules based on example data


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.pyck.cloud/graphql-api/mutations/generatejsonschema.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
