Content
Why Nested JSON in SQL Is So Painful
If you have ever exported data from Salesforce, NetSuite, or Zendesk into a database, you have probably stared at a JSON column and tried to write a WHERE clause against it.
PostgreSQL: jsonb_extract_path, ->>, and #>>
The -> and ->> Operators
Nested Paths with #>>
Querying Arrays with jsonb_array_elements
MySQL: JSON_EXTRACT and the ->> Operator
NetSuite Line Items with JSON_TABLE
SQL Server: JSON_VALUE and OPENJSON
OPENJSON for Arrays
Common Mistakes That Return NULL
Case sensitivity: JSON keys are case-sensitive
Array index: Arrays are 0-indexed
Wrong operator in PostgreSQL: -> returns JSON, ->> returns text
Escaped quotes in MySQL: JSON_EXTRACT returns quoted strings
How AI2SQL Handles JSON Queries
AI2SQL lets you describe what you want in plain English and generates the correct JSON extraction query for your target database. You do not have to remember whether it is jsonb_array_elements_text or JSON_TABLE or OPENJSON.
Quick Reference
PostgreSQL: payload ->> 'key' or payload #>> '{nested,key}'
MySQL: payload ->> '$.nested.key'
SQL Server: JSON_VALUE(payload, '$.nested.key')
When that happens, AI2SQL can save you the lookup time.


