declare @t1 as table( [id] int not null, [json_text] varc...

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, '[{"col1": "val111", "col2": "val112"}, {"col1": "val121", "col2": "val122"}]' union all
select 3, '[{"col1": "val311", "col2": "val312"}, {"col1": "val321", "col2": "val322"}, {"col1": "val331", "col2": "val332"}]';

/*select t1.id, 
JSON_VALUE(json.VALUE, '$.col1') as col1,
JSON_VALUE(json.VALUE, '$.col2') as col2
from @t1 as t1
cross apply OPENJSON (t1.json_text) AS json;*/

select * 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