Skip to content
Advertisement

How to extract list of values from JSON in SQL Server

In a SQL Server database, I have a table that contains 2 columns, ID and JSON. The JSON column contains JSON-formatted text. I have access to ISJSON, JSON_VALUE and JSON_QUERY, but not OPENJSON.

I am trying to write a query similar to the one below, that returns the ID column and all of the WorkstationID values. My query returns null. Can someone help me see what I am doing wrong? Below is an example of the JSON data I am working with, as well as my query, and what I expect the output to look like. Thanks for any help that can be offered!

UPDATE: As was discussed in the comments below, OPENJSON seems to be the easy way to do this, but this is not possible for me because my compatibility level is < 130. I have found that the following regex string can be used to extract all WorkstationID’s from the JSON.

WorkstationID”:”([0-9]{1,4})

Could using a regular expression like this be useful to return the list of all WorkstationID’s contained in the JSON in a table format like what is explained in a table format?

Advertisement

Answer

Given this is a one-off for you, I’ve written an inefficient JSON to XML converter for you to access your data.

Returns

Your JSON gets converted to the following XML:

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement