The JSON path array accessor accepts a range of elements to pick:
SELECT JSON_QUERY('["A", "B", "C"]', '$[1 to 2]'
WITH ARRAY WRAPPER
)
FROM …
The JSON path expression [1 to 2]
in this example returns the JSON elements "A"
and "B"
.
Primer: “JSON Path”
Other SQL/JSON path array accessors:
Last element: [last]
Multiple subscripts: [<e>, <e>, …]
The SQL/JSON path language first appeared in ISO/IEC 9075-2:2016 as part of optional feature T821, “Basic SQL/JSON query operators”.
You can’t catch up on 20 years of SQL evolution in one day. Subscribe the newsletter via E-Mail, Bluesky or RSS to gradually catch up and to keep modern-sql.com on your radar.
The essence of SQL tuning in 200 pages
Buy now!
(paperback and/or PDF)
Paperback also available at Amazon.com.
Markus offers SQL training and consulting for developers working at companies of all sizes.
Learn more »