How to fix PGRST102: Invalid JSON body in Supabase

SupabaseINTERMEDIATEMEDIUMUpdated Dec 22, 2025· 190 views

Supabase (PostgREST) returns PGRST102 when the JSON payload sent to a REST endpoint is malformed, contains syntax errors, or violates schema constraints. This error prevents the request from reaching the database and requires fixing the JSON structure before resubmitting.

Quick fix

Fixes PGRST102: Invalid JSON body

# Validate JSON with jq
echo '{"name": "test", "age": 25,}' | jq empty

# Or use Python
python3 -m json.tool <<< '{"name": "test", "age": 25}'
  1. Validate your JSON syntax
  2. Check data types against your table schema
  3. Verify JSON structure matches endpoint expectations
  4. Use the Supabase client library for automatic validation
supabase — error
# Validate JSON with jq
echo '{"name": "test", "age": 25,}' | jq empty
# Or use Python
python3 -m json.tool <<< '{"name": "test", "age": 25}'
PGRST102: Invalid JSON body

What this error means

PostgREST, the REST API layer in front of Supabase's PostgreSQL database, validates every JSON payload before passing it to the database. The "Invalid JSON body" error (PGRST102) occurs when PostgREST cannot parse the JSON due to syntax errors, malformed structure, or when the JSON violates the expected schema for the target table. This validation happens before any database operations, ensuring that only valid data reaches your tables. The error is part of PostgREST's Group 1 API request errors, which handle HTTP semantics and payload validation.

Typical symptoms

  • POST/PATCH/PUT requests to Supabase REST endpoints return HTTP 400/415 with "PGRST102: Invalid JSON body"
  • Supabase client library calls fail with JSON parsing errors even though the request appears valid
  • Data insertion/updates fail despite correct authentication and permissions
  • Error occurs when sending JSON with trailing commas, missing quotes, or incorrect data types
  • Requests work with simple JSON but fail with nested objects or arrays

Common causes

  1. JSON syntax errors: trailing commas, missing quotes, unescaped characters, or malformed structure
  2. Data type mismatches: sending strings where numbers are expected, or vice versa
  3. Missing required fields that have NOT NULL constraints in the database schema
  4. JSON that exceeds column size limits or contains unsupported characters
  5. Sending JSON arrays when the endpoint expects a single object, or vice versa
  6. Character encoding issues or BOM (Byte Order Mark) in the JSON payload

How to fix "PGRST102: Invalid JSON body"

1Validate your JSON syntax

Use a JSON validator to check for syntax errors. Common issues include trailing commas, missing quotes, and unescaped control characters.

bash
# Validate JSON with jq
echo '{"name": "test", "age": 25,}' | jq empty

# Or use Python
python3 -m json.tool <<< '{"name": "test", "age": 25}'

If the validator reports errors, fix them before sending to Supabase. Pay special attention to:
- Trailing commas after the last item in objects/arrays
- Missing quotes around property names
- Unescaped quotes within strings
- Invalid control characters

2Check data types against your table schema

Compare your JSON payload against your Supabase table schema. Ensure data types match (strings vs numbers, booleans vs strings).

sql
-- Check your table schema in Supabase SQL Editor
SELECT column_name, data_type, is_nullable
FROM information_schema.columns
WHERE table_name = 'your_table';

Common mismatches:
- Sending string "25" for integer column
- Sending boolean true/false as string "true"/"false"
- Sending null for NOT NULL columns
- Exceeding varchar length limits

3Verify JSON structure matches endpoint expectations

Different Supabase endpoints expect different JSON structures:

javascript
// For inserting a single row - send object
const correctSingle = { name: 'John', age: 30 };

// For inserting multiple rows - send array of objects
const correctMultiple = [
  { name: 'John', age: 30 },
  { name: 'Jane', age: 25 }
];

// For upsert - include primary key
const correctUpsert = { id: 1, name: 'John', age: 30 };

// For update - partial object is fine
const correctUpdate = { age: 31 }; // PATCH request

Check if you're sending an array when the endpoint expects an object, or vice versa.

4Use the Supabase client library for automatic validation

The Supabase JavaScript/TypeScript client handles JSON serialization automatically and provides better error messages:

javascript
import { createClient } from '@supabase/supabase-js';

const supabase = createClient(SUPABASE_URL, SUPABASE_ANON_KEY);

// Let the client handle JSON serialization
const { data, error } = await supabase
  .from('users')
  .insert({ name: 'John', age: 30 });

if (error) {
  console.error('Detailed error:', error);
  // Error will include specific validation details
}

The client library also:
- Automatically sets Content-Type header
- Handles JSON.stringify() for you
- Provides TypeScript types for schema validation

5Check for encoding and special character issues

Non-UTF8 encoding or special characters can break JSON parsing:

javascript
// Bad: BOM (Byte Order Mark) at start
const badJson = '{"name": "test"}';

// Bad: Unescaped quotes
const badJson2 = '{"message": "He said "hello""}';

// Good: Escaped quotes
const goodJson = '{"message": "He said \"hello\""}';

// Check encoding
console.log('First char code:', jsonString.charCodeAt(0));
// If 65279 (0xFEFF), you have a BOM

Solutions:
- Ensure your JSON is UTF-8 encoded
- Escape special characters properly
- Remove any BOM from the beginning of files

6Test with minimal payload to isolate the issue

Create the simplest possible JSON that should work, then gradually add complexity:

javascript
// Start with minimal valid JSON
const minimal = {};

// Add one field at a time
const withOneField = { id: 1 };

// Test each field individually
const testFields = [
  { name: 'test' },
  { age: 25 },
  { active: true },
  { tags: ['a', 'b'] }
];

// Use curl for direct testing
curl -X POST https://your-project.supabase.co/rest/v1/table   -H "apikey: YOUR_ANON_KEY"   -H "Authorization: Bearer YOUR_JWT"   -H "Content-Type: application/json"   -d '{}'  # Start empty, then add fields

This helps identify which specific field or structure causes the error.

Advanced notes

PostgREST uses PostgreSQL's JSONB type for parsing and validation, which is strict about JSON syntax. The PGRST102 error occurs during the JSON parsing phase before any database constraints are checked. If you're working with large JSON payloads, consider:
1. Using PostgreSQL's JSONB operators for partial updates instead of sending full objects
2. Implementing row-level security policies that might reject certain JSON structures
3. Using database triggers that validate JSON content
4. Setting up JSON schema validation in PostgreSQL if you need strict structural validation

Remember that PostgREST follows RFC 8259 for JSON parsing, so ensure your JSON complies with this standard.

Frequently asked questions

What does "PGRST102: Invalid JSON body" mean?
PostgREST, the REST API layer in front of Supabase's PostgreSQL database, validates every JSON payload before passing it to the database. The "Invalid JSON body" error (PGRST102) occurs when PostgREST cannot parse the JSON due to syntax errors, malformed structure, or when the JSON violates the expected schema for the target table. This validation happens before any database operations, ensuring that only valid data reaches your tables.
How do I fix "PGRST102: Invalid JSON body"?
Supabase (PostgREST) returns PGRST102 when the JSON payload sent to a REST endpoint is malformed, contains syntax errors, or violates schema constraints. This error prevents the request from reaching the database and requires fixing the JSON structure before resubmitting.
What causes "PGRST102: Invalid JSON body"?
JSON syntax errors: trailing commas, missing quotes, unescaped characters, or malformed structure Data type mismatches: sending strings where numbers are expected, or vice versa Missing required fields that have NOT NULL constraints in the database schema
Is the "PGRST102: Invalid JSON body" error serious?
It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.

Official resources & further reading