将数据从 Json 提取到 Table,其中 Id 在 Key 中
Extract the Data from Json to Table where Id is in Key
我正在尝试使用 SQL 函数 JSON_QUERY(表达式 [,路径])将下面的 Json 转换为 table。当我使用它时,我无法定义路径,因为 Id 在密钥中并且 id 超时更改。有什么办法可以 convert/load 这个 json 格式变成 table?
您可以使用 OPENJSON table 值函数实现它:
SELECT ch.[key] as checklistId,
JSON_VALUE (ch.[value] ,'$.isChecked') as isChecked,
JSON_VALUE (ch.[value],'$.orderHint') as orderHint
FROM OPENJSON (@json,'$.checklist') ch;
我正在尝试使用 SQL 函数 JSON_QUERY(表达式 [,路径])将下面的 Json 转换为 table。当我使用它时,我无法定义路径,因为 Id 在密钥中并且 id 超时更改。有什么办法可以 convert/load 这个 json 格式变成 table?
您可以使用 OPENJSON table 值函数实现它:
SELECT ch.[key] as checklistId,
JSON_VALUE (ch.[value] ,'$.isChecked') as isChecked,
JSON_VALUE (ch.[value],'$.orderHint') as orderHint
FROM OPENJSON (@json,'$.checklist') ch;