Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parse JSON string in sql

I have a column of JSON strings in my table, I'm using SQL Server 2008. Any Ideas on how to parse the JSON string and extract a specific value?

Here's my JSON String:

{"id":1234,"name":"Lasagne al frono","description":"Placerat nisi turpis, dictumst nasceture ete etiam mus nec cum platea tempori zillest. Nisi niglue, augue adipiscing ete dignissim sed mauris augue, eros!","image":"images/EmptyProduct.jpg","cartImage":"images/ArabianCoffee.jpg","basePrice":54.99,"priceAttribute":"itemPrice","attributes":[{"type":"Addons","label":"Side","attributeName":"Side","display":"Small","lookupId":8},{"type":"Addons","label":"Drink","attributeName":"drink","display":"Small","lookupId":5},{"label":"add note","type":"Text","attributeName":"notes","display":"Wide","lookupId":null}]}

I need to extract the value of "name", Any Help?

like image 260
Silvia H Avatar asked Dec 15 '22 20:12

Silvia H


1 Answers

Since sql server has no JSON support built in, you'd need to parse this manually, which would get complicated.

However, you could always use somebody else's JSON parsing library.

like image 174
Sam Peacey Avatar answered Jan 02 '23 09:01

Sam Peacey