Skip to main content
Improved formatting.
Source Link
help-info.de
  • 7.4k
  • 17
  • 43
  • 43

I had the same symptom as in the title of this thread but ended up having a different problem that you may encounter. I have a column containing JSON data in SQL Server 2016 (stored in the recommended nvarchar SQL datatype). When hitting the WEB API in the browser all double-quotes in my JSON column were being escaped (backslash-quote). In my javascript GUI I was doing a JSON.parse on the resulting JSON, and not able to dereference the JSON data. I figured at first that the problem was the backslashes etc. However, it turned out that my javascript code was able to work with the escaped code just fine. The real issue was that I was try to dereference the JSON data at a sublevel before running JSON.parse on the column data.

To be more concrete...imagine one row of data in the db is returned as json ('application/json' data returned to the browser)..lets call is myJSONdata. All data for all columns are returned as JSON, but one particular column (call it myJSONcolumn) has a JSON object that is several levels deep.

Dereferencing the sublevel like this will fail:

JSON.parse(myJSONdata["myJSONcolumn"]["sublevel1"])

JSON.parse(myJSONdata["myJSONcolumn"]["sublevel1"]) 

but this will work:

JSON.parse(myJSONdata["myJSONcolumn"])["sublevel1"]

JSON.parse(myJSONdata["myJSONcolumn"])["sublevel1"] 

I had the same symptom as in the title of this thread but ended up having a different problem that you may encounter. I have a column containing JSON data in SQL Server 2016 (stored in the recommended nvarchar SQL datatype). When hitting the WEB API in the browser all double-quotes in my JSON column were being escaped (backslash-quote). In my javascript GUI I was doing a JSON.parse on the resulting JSON, and not able to dereference the JSON data. I figured at first that the problem was the backslashes etc. However, it turned out that my javascript code was able to work with the escaped code just fine. The real issue was that I was try to dereference the JSON data at a sublevel before running JSON.parse on the column data.

To be more concrete...imagine one row of data in the db is returned as json ('application/json' data returned to the browser)..lets call is myJSONdata. All data for all columns are returned as JSON, but one particular column (call it myJSONcolumn) has a JSON object that is several levels deep.

Dereferencing the sublevel like this will fail:

JSON.parse(myJSONdata["myJSONcolumn"]["sublevel1"])

but this will work:

JSON.parse(myJSONdata["myJSONcolumn"])["sublevel1"]

I had the same symptom as in the title of this thread but ended up having a different problem that you may encounter. I have a column containing JSON data in SQL Server 2016 (stored in the recommended nvarchar SQL datatype). When hitting the WEB API in the browser all double-quotes in my JSON column were being escaped (backslash-quote). In my javascript GUI I was doing a JSON.parse on the resulting JSON, and not able to dereference the JSON data. I figured at first that the problem was the backslashes etc. However, it turned out that my javascript code was able to work with the escaped code just fine. The real issue was that I was try to dereference the JSON data at a sublevel before running JSON.parse on the column data.

To be more concrete...imagine one row of data in the db is returned as json ('application/json' data returned to the browser)..lets call is myJSONdata. All data for all columns are returned as JSON, but one particular column (call it myJSONcolumn) has a JSON object that is several levels deep.

Dereferencing the sublevel like this will fail:

JSON.parse(myJSONdata["myJSONcolumn"]["sublevel1"]) 

but this will work:

JSON.parse(myJSONdata["myJSONcolumn"])["sublevel1"] 
added 1097 characters in body
Source Link
sarora
  • 914
  • 9
  • 20

I had the same symptom as in the title of this thread but ended up beinghaving a different problem that othersyou may encounter. I have a column containing JSON data in SQL Server 2016 (stored in the recommended nvarchar SQL datatype). When hitting the WEB API in the browser all double-quotes in my JSON column were being escaped (backslash-quote). In my javascript GUI I was doing a JSON.parse on the resulting JSON, and not able to dereference the JSON data. I figured at first that the problem was the backslashes etc. However, it turned out that my javascript code was able to work with the escaped code just fine. The real issue was that I was try to dereference the JSON data at a sublevel before running JSON.parse on the column data.

To be more concrete...imagine one row of data in the db is returned as json ('application/json' data returned to the browser)..lets call is myJSONdata. All data for all columns are returned as JSON, but one particular column (call it myJSONcolumn) has a JSON object that is several levels deep.

Dereferencing the sublevel like this will fail:

JSON.parse(myJSONdata["myJSONcolumn"]["sublevel1"])

but this will work:

JSON.parse(myJSONdata["myJSONcolumn"])["sublevel1"]

I had the same symptom as the title of this but ended up being a different problem that others may encounter...

I had the same symptom as in the title of this thread but ended up having a different problem that you may encounter. I have a column containing JSON data in SQL Server 2016 (stored in the recommended nvarchar SQL datatype). When hitting the WEB API in the browser all double-quotes in my JSON column were being escaped (backslash-quote). In my javascript GUI I was doing a JSON.parse on the resulting JSON, and not able to dereference the JSON data. I figured at first that the problem was the backslashes etc. However, it turned out that my javascript code was able to work with the escaped code just fine. The real issue was that I was try to dereference the JSON data at a sublevel before running JSON.parse on the column data.

To be more concrete...imagine one row of data in the db is returned as json ('application/json' data returned to the browser)..lets call is myJSONdata. All data for all columns are returned as JSON, but one particular column (call it myJSONcolumn) has a JSON object that is several levels deep.

Dereferencing the sublevel like this will fail:

JSON.parse(myJSONdata["myJSONcolumn"]["sublevel1"])

but this will work:

JSON.parse(myJSONdata["myJSONcolumn"])["sublevel1"]

Source Link
sarora
  • 914
  • 9
  • 20

I had the same symptom as the title of this but ended up being a different problem that others may encounter...