Skill 1.3.3
Write queries that include JSON functions, such as JSON_OBJECT, JSON_ARRAY, JSON_ARRAYAGG, JSON_CONTAINS, OPENJSON, and JSON_VALUE
Key Concepts
To construct JSON, JSON_OBJECT('id':ProductID, 'name':Name) builds an object from key-value pairs, JSON_ARRAY(a, b, c) builds an array, and the aggregate JSON_ARRAYAGG(expr ORDER BY ...) turns a group of rows into one array (with JSON_OBJECTAGG for objects). NULL ON NULL or ABSENT ON NULL controls whether NULL values appear. FOR JSON PATH formats a whole result set, using dotted aliases for nesting.
To read JSON, JSON_VALUE(doc, '$.path') returns a scalar (with an optional RETURNING type), JSON_QUERY returns an object or array, JSON_PATH_EXISTS tests whether a path exists, and JSON_CONTAINS(doc, value, '$.path') returns 1 when a value is found at the path, including inside arrays with [*]. OPENJSON shreds an array into rows, and its WITH clause maps properties to typed columns. Paths use lax mode by default (missing paths return NULL); strict mode raises an error.