Since you are using MySQL 5.7, you don't have support for the JSON_TABLE() function, which would be the solution for the query you describe.

SELECT j.tag, COUNT(*) AS count
FROM mytable CROSS JOIN 
JSON_TABLE(tags, '$.en[*]' COLUMNS(tag VARCHAR(10) PATH '$.') AS j
GROUP BY j.tag
ORDER BY count DESC;

I would strongly recommend that you store your multi-valued data in normal columns and rows, not in JSON. Then the query would become more straightforward:

SELECT `tag`, COUNT(*) AS count
FROM en_tags
GROUP BY `tag`
ORDER BY count DESC;
Answer from Bill Karwin on Stack Overflow
🌐
MySQL
dev.mysql.com › doc › refman › 8.4 › en › json-search-functions.html
MySQL :: MySQL 8.4 Reference Manual :: 14.17.3 Functions That Search JSON Values
mysql> EXPLAIN SELECT c->>'$.name' ... is similar to how MySQL expands the -> operator in the same circumstances. ... Returns the keys from the top-level value of a JSON object as a JSON array, or, if a path argument is given, the top-level keys from the selected pat...
Discussions

Extract data from one special object out of JSON array in mySQL - Databases - SitePoint Forums | Web Development & Design Community
I have a mySQL database with a table named “orders”. In this table I have a column named ids which is JSON. More on sitepoint.com
🌐 sitepoint.com
0
January 13, 2024
mysql - Extract JSON object inside of an JSON array then search base on ID - Database Administrators Stack Exchange
I have a problem extracting data in the JSON column. I'm new to this JSON method, unlike relation tables. Sample Table: every minute/second all websites activity will be saved in 1 column alongside More on dba.stackexchange.com
🌐 dba.stackexchange.com
February 2, 2022
How to get a specific object in an JSON array in MySQL? - Stack Overflow
I know I can extract the data to a JSON_TABLE() to do the filtering but I don't get the original object back(unless I recreate it back) and the solution is not dynamic. Can this kind of array filtering can really be done in MySQL? More on stackoverflow.com
🌐 stackoverflow.com
MySQL search json value by key in array - Stack Overflow
0 MySQL JSON - How to extract a "value" for a particular "Key" from an array of Named Key/Value Pairs More on stackoverflow.com
🌐 stackoverflow.com
🌐
DataCamp
datacamp.com › doc › mysql › mysql-json-extract
MySQL JSON_EXTRACT() Function: Usage & Examples
The `JSON_EXTRACT()` function in MySQL is used to extract data from JSON documents. It allows you to retrieve specific values from JSON-encoded data stored in your database. `JSON_EXTRACT()` is commonly used when you need to access or manipulate specific data within a JSON object or array.
🌐
SitePoint
sitepoint.com › databases
Extract data from one special object out of JSON array in mySQL - Databases - SitePoint Forums | Web Development & Design Community
January 13, 2024 - Hi I have a mySQL database with a table named “orders”. In this table I have a column named ids which is JSON. The JSON looks like [ { "type" : "master", "id" : "100" }, { "type" : "slave", "id" : "101" }, { "type" : "slave", "id" : "102" }, .... ] I need a select, which gives me the id of the object which is of type master.
🌐
DEV Community
dev.to › gbhorwood › mysql-using-json-data-and-not-hating-it-6lc
mysql: using json data and not hating it - DEV Community
May 29, 2024 - SELECT JSON_EXTRACT(some_json, '$.tracks**.title') as side_a_and_side_be FROM some_data WHERE id = 1; +----------------------------------------------+ | side_a_and_side_be | +----------------------------------------------+ | ["Kiss and Ride", "No You Don't", "Queenie"] | +----------------------------------------------+ in that example, ** matches both A and B. very powerful stuff. we can also use ranges when defining our array indexes.
🌐
Holistics
holistics.io › blog › how-to-extract-nested-json-data-in-mysql-8-0
How to extract nested JSON data in MySQL 8.0
November 27, 2020 - For DB users who work with JSON string in MySQL 8.0, a guide on how to unnest, flatten, and extract nested JSON data using JSON_EXTRACT and JSON_TABLE.
🌐
DB Vis
dbvis.com › thetable › json_extract-mysql-function-complete-guide
JSON_EXTRACT MySQL Function: Complete Guide
September 10, 2025 - If there are multiple path expressions, the MySQL JSON_EXTRACT function returns a JSON array of values, like in this example:
Find elsewhere
🌐
MySQL
dev.mysql.com › doc › refman › 9.6 › en › json.html
MySQL :: MySQL 9.6 Reference Manual :: 13.5 The JSON Data Type
Let $ refer to this JSON array with three elements: ... Because $[1] and $[2] evaluate to nonscalar values, they can be used as the basis for more-specific path expressions that select nested values. Examples: ... As mentioned previously, path components that name keys must be quoted if the unquoted key name is not legal in path expressions. Let $ refer to this value: ... mysql> SELECT JSON_EXTRACT('{"a": 1, "b": 2, "c": [3, 4, 5]}', '$.*'); +---------------------------------------------------------+ | JSON_EXTRACT('{"a": 1, "b": 2, "c": [3, 4, 5]}', '$.*') | +---------------------------------
🌐
Medium
medium.com › @ozhanli › mastering-json-array-search-in-mysql-8-finding-empty-elements-a8191ad405c
Mastering JSON Array Search in MySQL 8: Finding Empty Elements | by ozhanli | Medium
August 17, 2023 - Mastering JSON Array Search in MySQL 8: Finding Empty Elements MySQL 8 has brought forth a host of JSON features, streamlining the process of identifying empty arrays within JSON data …
🌐
DataCamp
datacamp.com › doc › mysql › mysql-json-array
MySQL JSON_ARRAY() Function: Usage & Examples
MySQL `JSON_ARRAY()` includes `NULL` as a JSON null. Note that SQL `NULL` is different from JSON `null`, which might affect downstream processing. Leverage JSON functions. Use other JSON functions like `JSON_EXTRACT()` in combination with `JSON_ARRAY()` for comprehensive JSON data manipulation.
🌐
MySQL
dev.mysql.com › doc › refman › 8.4 › en › json-creation-functions.html
MySQL :: MySQL 8.4 Reference Manual :: 14.17.2 Functions That Create JSON Values
Two aggregate functions generating JSON values are available. JSON_ARRAYAGG() returns a result set as a single JSON array, and JSON_OBJECTAGG() returns a result set as a single JSON object.
Top answer
1 of 3
7

There is a way to solve this in SQL 5.7. I will go step by step in composing the solution. The goal is to find the strength of the knight.

I am going to use the same sample table as previous post:

create table mytable ( mycol json );

insert into mytable set mycol = '[{"Race": "Orc", "strength": 14}, {"Race": "Knight", "strength": 7}]';

First, get an array of only the races.

select json_extract(mycol, '$[*].Race') from mytable;
+----------------------------------+
| json_extract(mycol, '$[*].Race') |
+----------------------------------+
| ["Orc", "Knight"]                |
+----------------------------------+

Then, search for the Knight in this array (and unquote it).

select json_unquote(json_search(json_extract(mycol, '$[*].Race'), 'one', 'Knight')) from mytable;
+------------------------------------------------------------------------------+
| json_unquote(json_search(json_extract(mycol, '$[*].Race'), 'one', 'Knight')) |
+------------------------------------------------------------------------------+
| $[1]                                                                         |
+------------------------------------------------------------------------------+

Having found the index, get this element from the array.

select json_extract(mycol, json_unquote(json_search(json_extract(mycol, '$[*].Race'), 'one', 'Knight'))) from mytable;
+---------------------------------------------------------------------------------------------------+
| json_extract(mycol, json_unquote(json_search(json_extract(mycol, '$[*].Race'), 'one', 'Knight'))) |
+---------------------------------------------------------------------------------------------------+
| {"Race": "Knight", "strength": 7}                                                                 |
+---------------------------------------------------------------------------------------------------+

Then get the strength of this element.

select json_extract(json_extract(mycol, json_unquote(json_search(json_extract(mycol, '$[*].Race'), 'one', 'Knight'))), '$.strength') as strength from mytable;
+----------+
| strength |
+----------+
| 7        |
+----------+

You can repeat this on other fields to create other columns.

2 of 3
6

You're essentially meaning to apply selection and projection to the array elements and object fields of your JSON document. You need to do something like a WHERE clause to select a "row" within the array, and then do something like picking one of the fields (not the one you used in your selection criteria).

These are done in SQL using the WHERE clause and the SELECT-list of columns, but doing the same with JSON isn't something you can do easily with functions like JSON_SEARCH() and JSON_CONTAINS().

The solution MySQL 8.0 provides is the JSON_TABLE() function to turn a JSON document into a virtual derived table — as though you had defined conventional rows and columns. It works if the JSON is in the format you describe, an array of objects.

Here's a demo I did by inserting your example data into a table:

create table mytable ( mycol json );

insert into mytable set mycol = '[{"Race": "Orc", "strength": 14}, {"Race": "Knight", "strength": 7}]';

SELECT j.* FROM mytable, JSON_TABLE(mycol, 
  '$[*]' COLUMNS (
    race VARCHAR(10) PATH '$.Race', 
    strength INT PATH '$.strength'
  )
) AS j;
+--------+----------+
| race   | strength |
+--------+----------+
| Orc    |       14 |
| Knight |        7 |
+--------+----------+

Now you can do things you normally do with SELECT queries, like selection and projection:

SELECT j.strength FROM mytable, JSON_TABLE(mycol, '$[*]' 
  COLUMNS (
    race VARCHAR(10) PATH '$.Race', 
    strength INT PATH '$.strength'
  )
) AS j 
WHERE j.race = 'Orc'
+----------+
| strength |
+----------+
|       14 |
+----------+

This has a couple of problems:

  1. You need to do this every time you query the JSON data, or else create a VIEW to do it.

  2. You said you don't know the attribute fields, but to write a JSON_TABLE() query, you must specify the attributes you want to search and project in your query. You can't use this for totally undefined data.

I've answered quite a number of similar questions about using JSON in MySQL. I've observed that when you want to do this sort of thing, treating a JSON document like a table so you can apply condition in the WHERE clause to fields within your JSON data, then all your queries get a lot more difficult. Then you start feeling like you would have been better off spending a few minutes to define your attributes so you could write simpler queries.

🌐
GitHub
gist.github.com › ziadoz › b2e22f7e57c2eb5fbd3d4e4dc3eebd8f
MySQL 8 - Search Indexed JSON Arrays · GitHub
MySQL 8 - Search Indexed JSON Arrays · Raw · mysql8_indexed_json_arrays.sql · This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
🌐
DevOps.dev
blog.devops.dev › how-to-manipulate-json-arrays-in-mysql-tables-70d32e95d15d
How to manipulate JSON Arrays in MySQL Tables | by mani_ gedit | DevOps.dev
October 3, 2022 - DELIMITER $$DROP FUNCTION IF EXISTS `set_objects_key` $$CREATE FUNCTION `set_objects_key` (data_array JSON, object_key varchar(28), object_value varchar(128) ) RETURNS JSONDETERMINISTICBEGIN DECLARE c_index INT default 0; DECLARE result_array JSON; DECLARE end_range INT; DECLARE temp_item JSON ; DECLARE temp_result JSON; DECLARE temp_key varchar(28); SELECT JSON_LENGTH(data_array) into end_range; SET result_array = JSON_ARRAY(); WHILE c_index < end_range DO select CONCAT('$[', c_index, ']') into temp_key; SELECT JSON_EXTRACT(data_array, temp_key) into temp_item; SELECT JSON_SET(temp_item, CONCAT('$.', object_key ) , object_value ) into temp_result; SELECT JSON_ARRAY_APPEND(result_array, '$', temp_result) into result_array; SET c_index = c_index + 1; END WHILE;RETURN result_array;END $$DELIMITER ;
🌐
MySQL
bugs.mysql.com › bug.php
MySQL Bugs: #94549: Iterating JSON Arrays and Objects
This is how I do it: mysql> select array,i,"do something with "||myArray.arrayElement -> from ( -> select array,number as i,json_unquote(json_extract(array,'$['||number||']')) as arrayElement -> from ( -> select json_array("this", "that", "The Other") as array -> ) as sample_data -> /* I use ...
🌐
HackerNoon
hackernoon.com › unlocking-the-power-of-json-in-mysql-tips-and-tricks
Unlocking the Power of JSON in MySQL: Tips and Tricks | HackerNoon
September 11, 2023 - In this article, I will explain how and why you should use the JSON data type instead of TEXT.
🌐
Data and Open Source
ftisiot.net › mysqljson › how-to-extract-field-from-json-mysql
How to extract a field from a JSON object in MySQL | Data and Open Source
July 21, 2023 - select JSON_EXTRACT(json_data, '$.id') id, JSON_EXTRACT(json_data, '$.name') order_name from test; ... +------+----------------+ | id | order_name | +------+----------------+ | 778 | "Edward Olson" | +------+----------------+ Review all the JSON MySQL use-cases listed in the main page
🌐
MySQL
forums.mysql.com › index.php
MySQL :: MySQL Forums
September 4, 2008 - Document Store [X Dev API, Shell, JSON] Forum for MySQL Document Store [X Dev API, Shell, JSON] RSS · 97 · 165 · October 23, 2024 02:30AM · Backup · Forum for MySQL Backup. RSS · 1,357 · 3,299 · September 22, 2025 04:31AM · Data Recovery · Forum for Data Recovery.