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
0
votes
0 answers

Add EF Core 6 OPENJSON translation which passes the column name instead of string

I am working on a legacy project which uses SQL Server and stores JSON is some of the columns, which has been upgraded to EF Core 6. My main issue is that I have an old query which probably ran client-side in previous versions, but now fails at…
vgru
  • 49,838
  • 16
  • 120
  • 201
0
votes
1 answer

How to use OPENJSON to concatenate json Array in a column of a table

I have a column in SQL table which has a string value denoting a JSON array. I need to concatenate the array for comparison. There are multiple rows of this data and will be using a CURSOR to iterate through a set of values because no example of…
AsitK
  • 651
  • 1
  • 4
  • 14
0
votes
1 answer

Maximum 5000 rows returned using OPENJSON in SQL Server?

Using Azure Data Factory I have created a pipeline to upload any number of JSON files from Azure blob storage. I am loading the JSON data into a stage table with the following fields FileName varchar(200) JSONData nvarchar(max) Using the SQL…
xxvann
  • 1
  • 1
0
votes
1 answer

SQL Server reduce recurring XML nodes to JSON array

I have some XML in which every entry can contain some recurring elements. I'm trying to query it with OpenXML function and I want to reduce those elements to JSON arrays. My SQL looks like this: declare @idoc int, @xml xml = '
mike_grinin
  • 167
  • 1
  • 3
  • 13
0
votes
2 answers

Parsing json with SQL Server OpenJson

I am trying to parse the following json: declare @json nvarchar(2048) = N'{ "brand": "BMW", "year": 2019, "price": 1234.6, "colors": ["red","blue","black"] }' using: select a.CarBrand, a.CarModel, a.CarPrice, …
Coldchain9
  • 1,373
  • 11
  • 31
0
votes
0 answers

How to write Cross Apply OPENJSON in Criteria JPA

I have this entity @Entity public class ItemAdditionalInfo extends BaseEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long itemAdditionalInfoId; - - other columns…
SUVAM ROY
  • 103
  • 1
  • 10
0
votes
0 answers

JSON text is not properly formatted. Unexpected character '1' is found at position 0

i am getting this error in ssms while using openjson function JSON text is not properly formatted. Unexpected character '1' is found at position 0. Below is my code. DECLARE @json NVARCHAR(MAX) set…
shashank
  • 85
  • 8
0
votes
1 answer

How to fetch the json column data from database in SQL Server?

I have created a small demo app using .NET 6 with EF core and I am using Serilog to log exceptions into my database. Everything is working fine but now I want to display the log table details on my view (cshtml). Current log table columns…
Shaksham Singh
  • 491
  • 1
  • 5
  • 19
0
votes
0 answers

Join large table with JSON data with another table

We are using Azure SQL database having tables for saving document information, document approvers, package information etc. In document information table we save metadata in JSON string since metadata doesn't have fixed schema. We are facing issues…
Sushrut Paranjape
  • 429
  • 2
  • 4
  • 17
0
votes
1 answer

SQL Server OpenJson - retrieve row based on nested Json, querying multiple Json rows

Given the data table below, how can I retrieve only the row #3, querying the field "chave", based on multiple json rows? I want to retrieve the master row where the json field (NomeCampo = id and Valor = 3) and also (NomeCampo = id2 and Valor =…
RSilva
  • 6,753
  • 11
  • 43
  • 49
0
votes
1 answer

OpenJson store processed object in original form

DECLARE @JSON NVARCHAR(MAX) =…
VivekL
  • 65
  • 4
0
votes
1 answer

Why does recreate table make query for the table faster in Azure Synapse Analytics?

Recently, I found a strange behaviour in Azure Synapse Analytics while attempting to tune a store procedure for better performance. We have a slow performance issue when trying to parse 200 MB of JSON files into a table of Azure Synapse Analytics. I…
Ken Masters
  • 239
  • 2
  • 17
0
votes
1 answer

SQL Server 2019 - Build JSON with spread operator

I'm required to supply a json object like this: [ { id: '59E59BC82852A1A5881C082D5FFCAC10', user: { ...users[1], last_message: "16-06-2022", topic: "Shipment" }, unread: 2, …
Joe
  • 1,033
  • 1
  • 16
  • 39
0
votes
1 answer

OPENJSON SQL call to API with record pagination

I'm trying to consume an API, parse the data and then put it in a table. I've done several tests and I can't have all the records because the API has pagination.I've seen other posts and I can't find the solution DECLARE @token INT; DECLARE @ret…
0
votes
1 answer

OPENJSON does not detect duplicated Value

I need to import and parse some sales records into the database. Some customers have more than one product, therefore there are several orders with different product but with the same shipping address in the JSON Array. Problem arise when I try to…
Joe
  • 1,033
  • 1
  • 16
  • 39