.KeyValue() (SQL/JSON Path Item Method)


BigQueryDb2 (LUW)DuckDBH2MariaDBMySQLOracle DBPostgreSQLSQL ServerSQLite2013201520172019202120232025⚡ 3.9.1 - 3.51.0a⊘ 3.5.7 - 3.8.11⊘ 2008R2 - 2025✓ 12 - 18⊘ 9.4 - 11⚡ 23.26.1b⊘ 18c - 23.26.0b⚡ 12cR2b⊘ 11gR1 - 12cR1⊘ 5.0 - 9.6.0⚡ 10.2 - 12.2.2a⊘ 5.1 - 10.1⊘ 1.4.191 - 2.4.240⚡ 1.0.0 - 1.4.0a⚡ 11.5.0 - 12.1.3a⊘ 9.7 - 11.1⊘ 2.0
  1. ⚡Returns null
  2. ⚡Returns the input object
SELECT JSON_QUERY(j,'$.keyvalue()' WITH ARRAY WRAPPER)
  FROM (VALUES ('{"k":"v", "k2": 42}')) t(j)

This example returns the following JSON array where each entry represents a key/value pair from an object. The “id” property can be used to match those key/value pairs that originate from the same JSON input object together.

[ {"id": 0, "key": "k",  "value": "v"}
, {"id": 0, "key": "k2", "value": 42 }
]

Variants

Like any other item method, .keyvalue() can be used in the main expression as well as in filters.

Db2 (LUW) 12.1.3aaDuckDB 1.4.0aaMariaDB 12.2.2aaOracle DB 23.26.1bPostgreSQL 18SQLite 3.51.0a$.keyvalue()$ ? (@.keyvalue().key == "k2")
  1. Returns null
  2. Returns the input object

Normative References

The SQL/JSON-Path item method .keyvalue() is part of the optional feature T821, “Basic SQL/JSON query operators” of ISO/IEC 9075-2:2023.

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.

About the Author

Photo of Markus Winand

Markus Winand provides insights into SQL and shows how different systems support it at modern-sql.com. Previously he made use-the-index-luke.com, which is still actively maintained. Markus can be hired as trainer, speaker and consultant via winand.at.

Buy the Book

Cover of “SQL Performance Explained”: Squirrel running on grass

The essence of SQL tuning in 200 pages

Buy now!
(paperback and/or PDF)

Paperback also available at Amazon.com.

Hire Markus

Markus offers SQL training and consulting for developers working at companies of all sizes.
Learn more »

Connect with Markus Winand

Subscribe mailinglistsSubscribe the RSS feedMarkus Winand on LinkedInMarkus Winand on XINGMarkus Winand on MastodonMarkus Winand on Bluesky
Copyright 2015-2026 Markus Winand. All righs reserved.
Legal | Contact | NO WARRANTY | Trademarks | Privacy and GDPR