> ## Documentation Index
> Fetch the complete documentation index at: https://docs.paradedb.com/llms.txt
> Use this file to discover all available pages before exploring further.

# JSON Arrays

<Danger>
  **Legacy Docs:** This page describes our legacy API. It will be deprecated in
  a future version. Please use the [v2 API](/) where possible.
</Danger>

## Basic Usage

When dealing with JSON arrays, the array elements are “flattened” so that each
element can be searched individually. This means that if a JSON array is
encountered, each element in the array is treated as a separate value and
indexed accordingly. For example, given the following JSON structure:

```json theme={null}
{
  "metadata": {
    "colors": ["red", "green", "blue"]
  }
}
```

The JSON array in the colors field is flattened to emit separate terms for each
color. This allows for individual search queries like:

<CodeGroup>
  ```sql Function Syntax theme={null}
  SELECT description, metadata
  FROM mock_items
  WHERE id @@@ paradedb.term('metadata.colors' , 'blue')
  OR id @@@ paradedb.term('metadata.colors', 'red');
  ```

  ```sql JSON Syntax theme={null}
  SELECT description, metadata
  FROM mock_items
  WHERE id @@@
  '{
      "term": {
          "field": "metadata.colors",
          "value": "blue"
      }
  }'::jsonb
  OR id @@@
  '{
      "term": {
          "field": "metadata.colors",
          "value": "red"
      }
  }'::jsonb;
  ```
</CodeGroup>
