Searching for Values in JSON
This file contains 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.
Learn more about bidirectional Unicode characters
WITH dataset AS ( | |
SELECT * FROM (VALUES | |
(JSON '{"name": "Bob Smith", "org": "legal", "projects": ["project1"]}'), | |
(JSON '{"name": "Susan Smith", "org": "engineering", "projects": ["project1", "project2", "project3"]}'), | |
(JSON '{"name": "Jane Smith", "org": "finance", "projects": ["project1", "project2"]}') | |
) AS t (users) | |
) | |
SELECT json_extract_scalar(users, '$.name') AS user | |
FROM dataset | |
WHERE json_array_contains(json_extract(users, '$.projects'), 'project2') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment