As of PostgreSQL 9.4, you can use the ? operator:

select info->>'name' from rabbits where (info->'food')::jsonb ? 'carrots';

You can even index the ? query on the "food" key if you switch to the jsonb type instead:

alter table rabbits alter info type jsonb using info::jsonb;
create index on rabbits using gin ((info->'food'));
select info->>'name' from rabbits where info->'food' ? 'carrots';

Of course, you probably don't have time for that as a full-time rabbit keeper.

Update: Here's a demonstration of the performance improvements on a table of 1,000,000 rabbits where each rabbit likes two foods and 10% of them like carrots:

d=# -- Postgres 9.3 solution
d=# explain analyze select info->>'name' from rabbits where exists (
d(# select 1 from json_array_elements(info->'food') as food
d(#   where food::text = '"carrots"'
d(# );
 Execution time: 3084.927 ms

d=# -- Postgres 9.4+ solution
d=# explain analyze select info->'name' from rabbits where (info->'food')::jsonb ? 'carrots';
 Execution time: 1255.501 ms

d=# alter table rabbits alter info type jsonb using info::jsonb;
d=# explain analyze select info->'name' from rabbits where info->'food' ? 'carrots';
 Execution time: 465.919 ms

d=# create index on rabbits using gin ((info->'food'));
d=# explain analyze select info->'name' from rabbits where info->'food' ? 'carrots';
 Execution time: 256.478 ms
Answer from Snowball on Stack Overflow
Top answer
1 of 10
374

As of PostgreSQL 9.4, you can use the ? operator:

select info->>'name' from rabbits where (info->'food')::jsonb ? 'carrots';

You can even index the ? query on the "food" key if you switch to the jsonb type instead:

alter table rabbits alter info type jsonb using info::jsonb;
create index on rabbits using gin ((info->'food'));
select info->>'name' from rabbits where info->'food' ? 'carrots';

Of course, you probably don't have time for that as a full-time rabbit keeper.

Update: Here's a demonstration of the performance improvements on a table of 1,000,000 rabbits where each rabbit likes two foods and 10% of them like carrots:

d=# -- Postgres 9.3 solution
d=# explain analyze select info->>'name' from rabbits where exists (
d(# select 1 from json_array_elements(info->'food') as food
d(#   where food::text = '"carrots"'
d(# );
 Execution time: 3084.927 ms

d=# -- Postgres 9.4+ solution
d=# explain analyze select info->'name' from rabbits where (info->'food')::jsonb ? 'carrots';
 Execution time: 1255.501 ms

d=# alter table rabbits alter info type jsonb using info::jsonb;
d=# explain analyze select info->'name' from rabbits where info->'food' ? 'carrots';
 Execution time: 465.919 ms

d=# create index on rabbits using gin ((info->'food'));
d=# explain analyze select info->'name' from rabbits where info->'food' ? 'carrots';
 Execution time: 256.478 ms
2 of 10
71

You could use @> operator to do this something like

SELECT info->>'name'
FROM rabbits
WHERE info->'food' @> '"carrots"';
🌐
W3Schools
w3schools.com › js › js_json_arrays.asp
JSON Arrays
In JSON, array values must be of type string, number, object, array, boolean or null.
🌐
Alibaba Cloud
alibabacloud.com › help › en › analyticdb › analyticdb-for-mysql › developer-reference › json-functions
JSON functions and examples - AnalyticDB - Alibaba Cloud Documentation Center
September 27, 2025 - JSON functions and examples,AnalyticDB:This topic describes the JSON functions that are supported by AnalyticDB for MySQL clusters. JSON_ARRAY_CONTAINS: checks whether a JSON array contains the value specified by the value parameter.
🌐
Microsoft Learn
learn.microsoft.com › en-us › sql › t-sql › functions › json-array-transact-sql
JSON_ARRAY (Transact-SQL) - SQL Server | Microsoft Learn
The following example returns a JSON array with two elements. One element contains a JSON string and another element contains a JSON object.
🌐
GitHub
github.com › google › gson › issues › 876
JsonArray.contains checking for a String which has a single digit numeric. · Issue #876 · google/gson
March 30, 2016 - public static void main(String[] args) { String json = "[\"a\", \"2\", \"3\"]"; JsonElement element = new JsonParser().parse(json); Assert.assertTrue(element.isJsonArray()); JsonArray array = element.getAsJsonArray(); JsonElement idA = new JsonParser().parse("a"); Assert.assertTrue(array.contains(idA.getAsJsonPrimitive())); // Passes JsonElement id2 = new JsonParser().parse("2"); Assert.assertTrue(array.contains(id2.getAsJsonPrimitive())); // Fails } The first contains assertion passes checking for the string "a" however the second fails when I check for the string "2".
Author   RamakrishnanArun
🌐
JSON Schema
json-schema.org › understanding-json-schema › reference › array
JSON Schema - array
minContains and maxContains can be used with contains to further specify how many times a schema matches a contains constraint. These keywords can be any non-negative number including zero. ... The length of the array can be specified using the minItems and maxItems keywords.
Find elsewhere
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › api › system.text.json.nodes.jsonarray.contains
JsonArray.Contains(JsonNode) Method (System.Text.Json.Nodes) | Microsoft Learn
Determines whether an element is in the JsonArray. public: virtual bool Contains(System::Text::Json::Nodes::JsonNode ^ item);
🌐
TutorialsPoint
tutorialspoint.com › apache_tajo › apache_tajo_json_array_contains.htm
json_array_contains()
default> select json_array_contains('[10, 20, 30]', 10) as array_contains;
🌐
Microsoft Learn
learn.microsoft.com › en-us › sql › t-sql › functions › json-contains-transact-sql
JSON_CONTAINS (Transact-SQL) - SQL Server | Microsoft Learn
October 28, 2025 - A JSON array search value is contained in a target array if and only if every element in the search array is contained in some element of the target array.
🌐
JAXB
javaee.github.io › javaee-spec › javadocs › javax › json › JsonArray.html
JsonArray (Java(TM) EE 8 Specification APIs)
JsonArray instances are list objects that provide read-only access to the values in the JSON array. Any attempt to modify the list, whether directly or using its collection views, results in an UnsupportedOperationException. ... add, add, addAll, addAll, clear, contains, containsAll, equals, ...
🌐
StarRocks
docs.starrocks.io › reference › sql functions › json › json query and processing › json_contains
json_contains | StarRocks
Checks whether a JSON document contains a specific value or subdocument. If the target JSON document contains the candidate JSON value, the JSON_CONTAINS function returns 1.
🌐
Sumo Logic
sumologic.com › log search › search query language › search operators › jsonarraycontains
jsonArrayContains Search Operator | Sumo Logic Docs
May 22, 2023 - Use the jsonArrayContains operator to determine whether a JSON array contains a particular item.
🌐
ReqBin
reqbin.com › json › uzykkick › json-array-example
What is JSON Array?
The JSON array of strings contains only string elements, where each element is separated by a comma (,).