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!

2 Answers 2

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/

2
  • 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
    Commented Jun 12, 2012 at 16:18
  • 1
    There is native support starting from SQL Server 2016.
    – GSerg
    Commented Sep 17, 2016 at 7: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.

1
  • I have no control over the database structure or how information is stored. I'm just the integrator -_-
    – tbone14
    Commented Jun 12, 2012 at 16:07

Not the answer you're looking for? Browse other questions tagged or ask your own question.