---
number: 32925
slug: 32925-enhanced-type-inference-for-json-fields-in-supabase-js
published: 2025-01-20
discussion: https://github.com/orgs/supabase/discussions/32925
labels:
  - javascript
page: https://supabase.com/changelog/32925-enhanced-type-inference-for-json-fields-in-supabase-js
---

# Enhanced Type Inference for JSON Fields in supabase-js

TypeScript users, here's a cool new feature! Starting from [v2.48.0](https://github.com/supabase/supabase-js/releases/tag/v2.48.0), defining custom types for JSON fields in `supabase-js` and using them with the JSON selector is now easier, making your code more type-safe and intuitive.

### Quick Example

Define your custom JSON type:

```typescript
type CustomJsonType = {
  foo: string;
  bar: { baz: number };
  en: 'ONE' | 'TWO' | 'THREE';
};

export type Database = MergeDeep<
  DatabaseGenerated,
  {
    your_schema: {
      Tables: {
        your_table: {
          Row: {
            data: CustomJsonType | null;
          };
          // Optional: Use if you want type-checking for inserts and update
          // Insert: {
          //  data?: CustomJsonType | null;
          // };
          // Update: {
          //  data?: CustomJsonType | null;
          // };
        }
      }
      Views: {
        your_view: {
          Row: {
            data: CustomJsonType | null;
          };
        }
      }
    }
  }
>
```

### What You Get

Now, when you query your data:

```typescript
const res = await client
  .from('your_table')
  .select('data->bar->baz, data->en, data->bar');

if (res.data) {
  console.log(res.data);
  // TypeScript infers the shape of your JSON data:
  // [
  //   {
  //     baz: number;
  //     en: 'ONE' | 'TWO' | 'THREE';
  //     bar: { baz: number };
  //   }
  // ]
}
```

### Get Started

Start using this feature with our guides:
- [Generating Types](https://supabase.com/docs/guides/api/rest/generating-types)
- [Typescript Support](https://supabase.com/docs/reference/javascript/typescript-support)
- [Helper Types for Tables and Joins](https://supabase.com/docs/reference/javascript/select#helper-types-for-tables-and-joins)
