简体   繁体   中英

How to extract value from a JSON string with no Key?

I have a JSON column in one of the tables, and the JSON column has no key or property, only the value.

I tried to parse the column with JSON_Query and JSON_Value , but both of these functions only work if the JSON string has a key, but in my situation, the JSON string has no key.

So how can I parse the column from the top table to the bottom table in SQL Server like the image below?

在此处输入图片说明

Please try this:

DECLARE @Table TABLE (ID INT, [JSONColumn] NVARCHAR(MAX));
INSERT INTO @Table(ID,[JSONColumn])VALUES
     (151616,'["B0107C57WO","B066EYU4IY"]')
    ,(151617,'["B0088MD64S"]')
;

SELECT t.ID,j.[value]
FROM @Table t
CROSS APPLY OPENJSON(t.JSONColumn) j
;

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