JSON_VALUE and JSON_QUERY functions parse JSON text and return scalar values or objects/arrays on the path in JSON text.
DECLARE @json NVARCHAR(100) = '{"id": 1, "user":{"name":"John"}, "skills":["C#","SQL"]}'
SELECT
JSON_VALUE(@json, '$.id') AS Id,
JSON_VALUE(@json, '$.user.name') AS Name,
JSON_QUERY(@json, '$.user') AS UserObject,
JSON_QUERY(@json, '$.skills') AS Skills,
JSON_VALUE(@json, '$.skills[0]') AS Skill0
Result
Id | Name | UserObject | Skills | Skill0 |
---|---|---|---|---|
1 | John | {"name":"John"} | ["C#","SQL"] | C# |