12

I have a database in SQL Server 2008 and one particular table has information stored in fields as JSON-encoded arrays. I'm wondering there's a SQL-based approach to select out specific values within that JSON field?

I can, of course, just select the field and parse the information out myself, but I'm trying to avoid that if at all possible.

Thanks in advance!

tbone14
  • 133
  • 1
  • 1
  • 4

2 Answers2

6

There's nothing natively, but the first answer on the follow question references an article about parsing JSON objects in tSQL

Parse JSON in TSQL

For reference, the article of interest is here:

http://www.simple-talk.com/sql/t-sql-programming/consuming-json-strings-in-sql-server/

Community
  • 1
  • 1
Jon Egerton
  • 40,401
  • 11
  • 97
  • 129
  • Wow, the guy who wrote that article deserves our respect! @tbone14, this can be your solution, if you can add user-defined functions to the database. – bfavaretto Jun 12 '12 at 16:18
  • 1
    There is [native support](https://msdn.microsoft.com/en-us/library/dn921900.aspx) starting from SQL Server 2016. – GSerg Sep 17 '16 at 07:53
2

No (well, there's substring matching, but that would be slow and error-prone). If you're storing something you want to filter with SQL, do not use JSON, use separate columns/tables instead.

bfavaretto
  • 71,580
  • 16
  • 111
  • 150
  • I have no control over the database structure or how information is stored. I'm just the integrator -_- – tbone14 Jun 12 '12 at 16:07