简体   繁体   中英

How to parse the JSON arrays with OPENJSON

I have JSON data type in one of the columns in table as:

{
  "phones":["+16024000022"]
}

I tried to use next in order to parse this column to be readable:

SELECT phones, m.phone_numbers 
  FROM [AuthX].dbo.migration m
 CROSS APPLY OPENJSON( m.phone_numbers)
  WITH (
        phones NVARCHAR(50) '$'
       )

But I am getting null values in new column phones.

You can get a JSON array members in a form of key - value pairs. For example

SELECT  id, [key], value
FROM 
  (values (1, '{"phones":["+14809074223","+16024000022"]}')
) m (id,phone_numbers )
CROSS apply OPENJSON(m.phone_numbers, '$.phones');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM