0

Thank you in advance for answering my questions. I need to extract value using TSQL json_vlaue() from col1 = [{"key":"key1","value":"value1"}, {"key":"key2","value":"value2"}, ...] I can extract value like json_value(col1, '$[0].Value'), json_value(col1, '$[1].Value') ... However, there is no guarantee that the key-value pair order will always be the same. So I would need to extract value using keys rather than indexes.

Do I need to manipulate the string to {"key1":"value1", "key2":"value2"} then apply json_value(col, '$.key1') to get the value? If so, how do I preprocess the string?

Thanks!

fei
  • 1
  • Use OPEN_JSON() read about here https://learn.microsoft.com/en-us/sql/t-sql/functions/openjson-transact-sql?view=sql-server-ver15 – Amirhossein Mar 05 '22 at 10:18
  • What version of SQL Server? Only newer versions have JSON parsing natively. Also please include sample input and expected output to clarify your question – Stephan Mar 09 '22 at 03:52

0 Answers0