SQL SEVER: Counting Jason Array Size
Yichun Zhao
1 min read
Assuming your table is named error_log and the column containing the JSON string is error_data, and the JSON structure is like this:
{
"error_code": "some_code",
"error_message": ["message1", "message2", ...]
}
Your SQL Server query would look like this:
SELECT JSON_VALUE(error_data, '$.error_code') AS error_code, (SELECT COUNT(*) FROM OPENJSON(error_data, '$.error_message')) AS error_message_count FROM error_log;
0
Subscribe to my newsletter
Read articles from Yichun Zhao directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by