Questions tagged [open-json]

OpenJson is a T-SQL (SQL Server) built in table valued function, introduced in 2016 version. Use this tag with questions related to this command.

OpenJson was introduced in SQL Server 2016.
It takes in a nvarchar containing JSON data, with an optional nvarchar string containing a JSON Path Expression, and an optional With clause.

When the With clause is not supplied, OpenJson will return a table containing three columns:
Key (nvarchar(4000)), Value(nvarchar(max)) and Type (int).
values of the Type columns indicates the following:

Type    JSON data type
0       null
1       string
2       int
3       true/false
4       array
5       object

The With clause allows the user to explicitly define the columns of the table returned.
The With clause contains three parameters for each value to get from the JSON:
Column name, data type, and an optional JSON Path expression (if not supplied, OPENJSON will try to get a property with the same name as the target column.

If the json property extracted contains an inner json object, the AS JSON option can be specified with this column, to enable further JSON processing.

Articles

197 questions
1
vote
2 answers

How to join 2 tables, where data in one table has JSON data that needs to be parsed?

I'm struggling with some SQL, which should both join data from two tables together, but where I also need to parse a JSON array, into rows in the output table... Here are examples of my 2 tables that I'd like to join…
John McDonnell
  • 753
  • 1
  • 8
  • 24
1
vote
1 answer

Retrieve specific value from a JSON blob in MS SQL Server, using a property value?

In my DB I have a column storing JSON. The JSON looks like this: { "views": [ { "id": "1", "sections": [ { "id": "1", "isToggleActive": false, "components": [ { "id":…
Andrio
  • 1,852
  • 2
  • 25
  • 54
1
vote
1 answer

How to implement OPENJSON Having JSON code as a text inside a column. How do i use OPENJSON on the column of a table in AZURE SQL Dataware House?

Eg: RAW DATA | ORDER# | SUBORDER# | DISCOUNTS | |------- |-----------| -------------------------------| | 1 | 1-123 | '[{ discount:"1",amount:"1"}]' | | 1 | 1-123 | '[{ discount:"2",amount:"2"}]' | Want to…
syed ahmed
  • 13
  • 3
1
vote
1 answer

How to convert JSON column headers to lower case with OpenJson

I am trying to parse JSON data in SQL Server. The column headers are mixed case. Is there a way to convert it to upper or lower case. Below is the code: SELECT pr.AuditEvent_Id as [AuditEvent_HttpHeaders_Id] …
Ravi 1001
  • 25
  • 4
1
vote
1 answer

how to measure length of array inside array in json file using SQL OPENJSON function with cross APPLY

"table": [ { "name": "Emergency", "columns": [ { "name": "ab", …
1
vote
1 answer

Could not create the JSON-formatted Column in SQL Table with including NULL Values

I need to combine in one Table the SQL Data with columns, formatted as JSON. The Json columns are a vary length, from 4 to 5 Columns. So I need to add one optional NULL column to the JSON String, when the Length is 4. But if I put the 4-Places Json…
1
vote
2 answers

OPENJSON() SQL SERVER is returning null when the path is correct

This is the json i declare: DECLARE @json VARCHAR(MAX) = N' [ { "mTruckId": -35839339, "mPositionId": 68841545, "mPositionDateGmt": "laboris ipsum ullamco", "mLatitude": -36598160.205007434, "mLongitude": 54707169.834195435, …
Kevin
  • 31
  • 1
1
vote
1 answer

Parse JSON SQL with OPENJSON skipping OBJECTS

I'm trying to parse a json file using OPENJSON in Azure sql but I want to do a specific mapping in my new table. I have a json file which looks like this with many y0_1, y0_2, ....y0_380. {"proto": "01", "type": "A", "description":…
Zin
  • 23
  • 3
1
vote
1 answer

Is it possible to use wildcards as an argument for OPENJSON in SQL Server?

I have a nested JSON array consisting of outer keys that are numbers, each of which contain inner arrays that I need to import into a table in SQL Server. The JSON file is setup like so: { "121212": { "name": name of item, …
Mech
  • 101
  • 1
  • 7
1
vote
0 answers

With SQL 2017 -- does OPENJSON remove the escape sequences from the raw JSON data

SQL proc consuming JSON payload from Web Service but the data was escaped before being received in the procedure. I have a payload like this: { "RES_NBR_ID": "00000056566", "RES_SCRIPT_NM": "Test Script", "RES_SCRIPT_ID": "jcet2", …
user3297833
  • 141
  • 2
  • 9
1
vote
1 answer

Concatenate Array Values Using Json_Query

I have a table in a SQL Server database that stores JSON in one of its columns. The structure is as follows: Table Person | Name | ExtraInfo | |--------|:------------------------------------------:| | Bob | …
Dalsier
  • 377
  • 3
  • 14
1
vote
1 answer

How to insert only a portion of the JSON element into a SQL field

I'm using the following code in a SQL Server 2016 stored procedure and I would like to split the Journal ISSN value into 2 different fields. DECLARE @json nVARCHAR(MAX) = '[{"Journal ISSN" : "15221059, 15309932"}, {"Journal ISSN" :…
Bill
  • 1,423
  • 2
  • 27
  • 51
1
vote
2 answers

SQL Query to get the Json inside Json values by comma separated

I have the below Json object. I need to get the task names by comma (,) separated. { "Model": [ { "ModelName": "Test Model", "Object": [ { "ID": 1, "Name": "ABC", "Task" : [ …
Ashok Yaganti
  • 173
  • 5
  • 14
1
vote
1 answer

How to get multiple columns of values from OPENJSON and cross apply

I am using SQL Server inside Visual Studio 2019. I have downloaded a large JSON file for US Zip codes. My goal is to get all the properties from the fields, which look like this: and save their properties in my database. I don't care about…
ATCraiger
  • 109
  • 2
  • 13
1
vote
1 answer

Get multiple records per row from JSON array

I cannot get my head around how to extract multiple values from a single row, where there source is in a JSON array in every row. The setup may be a little bit silly, but that's how it is. Table: LogID [int] LogContent …
KoalaBear
  • 2,755
  • 2
  • 25
  • 29