🧚 ¡Escucha! Beekeeper Studio es una GUI de base de datos rápida, moderna y de código abierto Descargar
December 5, 2022 Por Matthew Rathbone

JSON_EXTRACT is a function in SQL that allows you to extract a value from a JSON string. It is often used with the SELECT statement to retrieve specific values from a table.

Tip: When you’re exploring JSON data in SQL, context is everything. Beekeeper Studio is a fast, cross-platform SQL editor that lets you browse tables, preview query results, and inspect structured data visually.

Simple JSON_EXTRACT example

Here is an example of how to use the JSON_EXTRACT function in a SELECT statement:

SELECT JSON_EXTRACT(json_column, '$.key1.key2')
FROM mytable
WHERE json_column IS NOT NULL;

In this example, the JSON_EXTRACT function is used to extract the value associated with the keys key1 and key2 from the json_column in the mytable table.

The function takes two arguments: the JSON string and the path to the value you want to extract. The path is specified using the $ sign to indicate the root of the JSON object, followed by a series of keys separated by dots (.).

If the JSON string in the json_column is structured like this:

{
  "key1": {
    "key2": "value"
  }
}

Then the JSON_EXTRACT function would return the string "value".

Using JSON_EXTRACT on nested data

You can also use the JSON_EXTRACT function to extract values from nested JSON objects. For example, if the JSON string in the json_column is structured like this:

{
  "key1": {
    "key2": {
      "key3": "value"
    }
  }
}

Then you can use the JSON_EXTRACT function with a path like this: $.key1.key2.key3 to extract the value "value".

Pro tip: If you often work with complex or nested JSON data, Beekeeper Studio’s JSON Sidebar makes it even easier — you can expand objects, search by key, and view deeply nested properties without running extra queries.

Beekeeper Studio’s JSON Sidebar showing structured JSON data with searchable keys and collapsible objects.

Using JSON_EXTRACT on arrays

Another useful feature of the JSON_EXTRACT function is that you can use it to extract values from JSON arrays. For example, if the JSON string in the json_column is structured like this:

{
  "key1": [
    {
      "key2": "value1"
    },
    {
      "key2": "value2"
    }
  ]
}

You can use the JSON_EXTRACT function with a path like this: $.key1[*].key2 to extract an array of values: ["value1", "value2"]. The [*] syntax indicates that you want to extract all values in the array, rather than just a specific index.

Using JSON_EXTRACT in other statements

In addition to the SELECT statement, you can also use the JSON_EXTRACT function in other SQL statements, such as INSERT, UPDATE, and DELETE, to manipulate JSON data in your database.

JSON_EXTRACT summary

Overall, the JSON_EXTRACT function is a powerful tool for working with JSON data in SQL. It allows you to easily extract specific values from JSON strings, even if the JSON is nested or contains arrays.

Need to convert JSON data to SQL INSERT statements? Try our free JSON to SQL Converter tool.

Try it in Beekeeper Studio

Whether you’re debugging API payloads or exploring event data, tools like Beekeeper Studio help you work faster. It’s the modern, cross-platform SQL editor for more than 20 databases, with powerful extras like the JSON Sidebar and an AI pair programmer to accelerate your database workflows.

Beekeeper Studio Es Una GUI de Base de Datos Gratuita y de Código Abierto

La mejor herramienta de consultas y editor SQL que he usado. Proporciona todo lo que necesito para gestionar mi base de datos. - ⭐⭐⭐⭐⭐ Mit

Beekeeper Studio es rápido, intuitivo y fácil de usar. Beekeeper soporta muchas bases de datos y funciona muy bien en Windows, Mac y Linux.

La versión de Linux de Beekeeper tiene todas las funciones, sin recortes ni compromisos de características.

Lo Que Dicen Los Usuarios Sobre Beekeeper Studio

★★★★★
"Beekeeper Studio reemplazó por completo mi antiguo flujo de trabajo con SQL. Es rápido, intuitivo y hace que trabajar con bases de datos sea agradable de nuevo."
— Alex K., Desarrollador de Bases de Datos
★★★★★
"He probado muchas GUIs de bases de datos, pero Beekeeper logra el equilibrio perfecto entre características y simplicidad. Simplemente funciona."
— Sarah M., Ingeniera Full Stack

¿Listo para Mejorar tu Flujo de Trabajo con SQL?

download Descargar Gratis