> 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/enums/jsontype.md).

# JSONType

JSONType enum for JSONB column ordering

Audience: Programmer

The `JSONType` enum specifies the type casting for extracted JSONB values when using JSONB column ordering in pagination queries. This ensures that values are properly compared and sorted according to their intended data type.

## Definition

```graphql
enum JSONType {
  NUMBER
  STRING
  BOOLEAN
}
```

## Values

### NUMBER

Cast the extracted JSONB value to numeric for number comparisons.

**Use when**: Sorting by numeric fields like quantities, weights, prices, or any numerical values stored in JSON.

**Example:**

```graphql
query {
  inventoryItems(
    orderBy: {
      direction: DESC,
      jsonPath: "attributes.weight",
      jsonType: NUMBER
    }
  ) {
    edges {
      node {
        id
        data
      }
    }
  }
}
```

### STRING

Cast the extracted JSONB value to text for string comparisons.

**Use when**: Sorting by text fields like names, descriptions, categories, or any string values stored in JSON.

**Example:**

```graphql
query {
  customers(
    orderBy: {
      direction: ASC,
      jsonPath: "company.name",
      jsonType: STRING
    }
  ) {
    edges {
      node {
        id
        data
      }
    }
  }
}
```

### BOOLEAN

Cast the extracted JSONB value to boolean for boolean comparisons.

**Use when**: Sorting by boolean flags like active/inactive status, feature flags, or any true/false values stored in JSON.

**Example:**

```graphql
query {
  inventoryItems(
    orderBy: {
      direction: DESC,
      jsonPath: "flags.isPriority",
      jsonType: BOOLEAN
    }
  ) {
    edges {
      node {
        id
        data
      }
    }
  }
}
```

## Usage Context

The `JSONType` enum is used exclusively with the `jsonType` field in OrderByInput types when performing JSONB column ordering. It works in conjunction with:

* `jsonPath`: Specifies the dot-notation path to the nested JSON field
* `jsonType`: Specifies how to cast the value (this enum)
* `direction`: Specifies sort direction (ASC or DESC)

## Type Casting Behavior

When you specify a `JSONType`, the database extracts the value at the specified `jsonPath` and casts it to the appropriate type for comparison:

| JSONType | Database Cast | Example Values                |
| -------- | ------------- | ----------------------------- |
| NUMBER   | numeric       | 1.5, 42, -10                  |
| STRING   | text          | "apple", "zebra", "Product A" |
| BOOLEAN  | boolean       | true, false                   |

## Important Notes

1. **Type Mismatch**: If the actual JSON value doesn't match the specified `JSONType`, the sorting behavior may be unexpected
2. **Null Values**: Missing or null values in the JSON path will be sorted as null regardless of `JSONType`
3. **Required with jsonPath**: The `jsonType` parameter is required when using `jsonPath` for JSONB ordering

## Complete Example

```graphql
query GetProductsByPriority {
  inventoryItems(
    first: 50,
    orderBy: {
      direction: DESC,
      jsonPath: "metadata.priority",
      jsonType: NUMBER
    },
    where: {
      dataHasKey: "metadata.priority"
    }
  ) {
    edges {
      node {
        id
        sku
        data
      }
      cursor
    }
    pageInfo {
      hasNextPage
      endCursor
    }
    totalCount
  }
}
```

## See Also

* [OrderByInput Types](/graphql-api/inputs/orderby-inputs.md) for complete ordering documentation
* [WithCustomData Interface](/graphql-api/interfaces/withcustomdata.md) for entities with the data field
* [Map Scalar](/graphql-api/scalars/map.md) for JSON data storage
* [Advanced JSON Field Queries](https://github.com/pyck-ai/docs/blob/main/graphql/advanced/json-field-queries.md) for filtering by JSON fields


---

# 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/enums/jsontype.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.
