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

OPENJSON unable to parse Portuguese characters

I'm trying to convert my JSON data into a table format in SQL Server Express 2019. Following are my JSON data: DECLARE @token INT; DECLARE @ret INT; DECLARE @url NVARCHAR(MAX); DECLARE @json AS TABLE(Json_Table NVARCHAR(MAX)) …
0
votes
1 answer

How to use OPENJSON if column is same in SQL?

My database table is created as : declare @library table (dependencies varchar(max)) insert into @library values('{"jar":"azure.com","maven":"azure.com","maven":"azure.com","maven":"azurebook.com"}') I am trying to have JSON as { "libraries":[ …
blac040
  • 127
  • 2
  • 9
0
votes
1 answer

Json to table without explicit key names

I have a table with an VARCHAR(MAX) column which stores JSON key value pairs. The JSON document schema is simply a different number of key value pairs, no nesting, nor arrays in there. I wish to build a query, which gives back the JSON in a tabular…
Avi
  • 1,066
  • 1
  • 15
  • 37
0
votes
1 answer

pyodbc azure sql server error in saving json using openjson

i want to save a json array into azure sql server, but i am getting this error: \serverCalls\sqlManager.py", line 95, in populateNewsLatest curse.execute(f""" pyodbc.Error: ('07002', '[07002] [Microsoft][ODBC Driver 17 for SQL Server]COUNT field…
0
votes
1 answer

Cannot Convert from String to Datetime while reading JSON data in SQL Server

DECLARE @JSON AS varchar(MAX) SET @JSON = '[ { "UserId": "XYZ12345", "LoginTime": "2021-12-25T07:48:59Z" }, { "UserId": "XYZ67890", "LoginTime": "2021-12-24T07:48:59Z" } ]' SELECT * FROM OPENJSON(@json) WITH ( UserId…
PavanKumar GVVS
  • 859
  • 14
  • 45
0
votes
3 answers

Parse JSON arrays using OPENJSON to table

I am confused how to shred my JSON data into a table because is not formatted with names for the arrays The actual JSON file is much bigger (19K lines) so I only pulled a small portion of it out (the first two of top level and a few from within…
user918967
  • 2,049
  • 4
  • 28
  • 43
0
votes
1 answer

How to extract array data from a JSON Column in SQL Server (OPENJSON, JSON_QUERY)

We have a SQL Server table that has a varchar(max) column with JSON data, but one of the fields is an array. Try as I might I can't get it to extract these one-per-row. In the past I've managed to do it where each array was made up of named members,…
Bobby Tables
  • 111
  • 3
  • 12
0
votes
2 answers

Reading JSON string and find the max value as integer

I have a JSON string as follows: DECLARE @json nvarchar(max) SET @json = '{"value": [ { "AEDAT": "20211110" }, { "AEDAT": "20211110" }, { "AEDAT": "20211110" }, { "AEDAT": "20211112" …
pythondumb
  • 1,187
  • 1
  • 15
  • 30
0
votes
1 answer

How to use OPENJSON Method with nested JSON having undetermined/dynamic path?

I'm working with an API that spits out a data in the form of dynamic json i.e. the location of some elements of json objects is not fixed, this leads to the path some elements in json arrays being dynamic. For example in the JSON object below the…
Walter
  • 79
  • 6
0
votes
1 answer

Can't get access to data from nested json's array

How to retrieve values from employment_types (type, salary) and skills (name, level) arrays and show them in columns? I tried with employment_types and it doesn't work not to mention skills: declare @json nvarchar(max) set @json = '[ { …
beginsql
  • 135
  • 7
0
votes
0 answers

How to form custom Json object in SQL Server

Required output: { "en-US": [ { "pagename": { "login": "login text", "register": "dsc" }, "page2": { "detail": "login text", "profile": "dsc" } } ], "fr-FR": [ { …
jishan siddique
  • 1,848
  • 2
  • 12
  • 23
0
votes
2 answers

how to filter data by Json string column in specific field

I have a Ms Sql Table. In this table, I store data in json format in my column named "DynamicData". What I want to do is to filter on this table. But to do this filtering according to different fields on the json data in my column named…
srkn
  • 45
  • 8
0
votes
1 answer

Trying to figure out syntax for OPENJSON query and stuck

I have been trying very hard to get data extracted from a JSON message I am trying to load into some tables. I can get this one to work that has one name/value pair above it, but another message has a second outer name/value pair. DECLARE @json…
Ricky S
  • 11
  • 4
0
votes
0 answers

Dynamic SQL Query to read the jSon file or string using OpenjSon

I have a very large JSON string. I am trying to read using SQL for some report, but the JSON has objects embedded within in at least couple of levels. How can I read all the Data using one SQL query using OpenJson? I tried in the following…
AbdulAleem
  • 63
  • 8
0
votes
1 answer

how to get the values of the each object from the JSON in SQL SERVER

DECLARE @json NVARCHAR(1000); SELECT @json = N' { "nodeinid": 1345, "data": [ { "nodenametext": "Plan for project", "nodedesctext": "plan description for execution", …