JSON Parsing - OPENJSON

0

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for professional and enthusiast programmers

declare @t1 as table(
  [id] int not null,
  [json_text] varchar(max) not null
);
insert into @t1
select 1, '[{"1col1": "val111", "col2": "val112"}, {"1col1": "val121", "col2": "val122"}]' union all
select 3, '[{"1col1": "val311", "col2": "val312"}, {"1col1": "val321", "col2": "val322"}, {"1col1": "val331", "col2": "val332"}]';

select t1.id, 
JSON_VALUE(json.VALUE, '$."1col1"') as col1,
JSON_VALUE(json.VALUE, '$.col2') as col2
from @t1 as t1
CROSS APPLY OPENJSON (t1.json_text) AS json

Enter Parameters

Options:
Switch to meta site
loading Hold tight while we fetch your results