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
1 answer

Loop through JSON in SQL Server 2016

I have a following JSON { "href": { "host": "localhost", "port": 2222 }, "name": "20190812", "scheduledStartTime": "2019-08-12T12:22:52.500-04:00", "parameters": { "1251226": { "value": { "instanceID": 219002, …
1
vote
1 answer

SQL query OpenJson with deep nested arrays loop

I know there a lot of similar questions and answers here. I've read most of them but I'm unable to query nested arrays in a JSON structure. I'm lost in the CROSS APPLY's. I'm actually querying a web API but for the sake of my question I've put it in…
joachimb
  • 11
  • 1
1
vote
0 answers

Can't expand JSON file in SQL Server using OPENJSON beyond 1st level

I am working with JSON that has been inserted into a SQL table and I have been trying to expand the dataset. So far I have been unable to expand beyond a single. The data looks like this in the database. A single record with JSON. I have been able…
Matt
  • 53
  • 1
  • 5
1
vote
1 answer

How to get json object property without using OPENJSON

Following is my script to get specific value(OldPTValue, NewPTValue) from table HistoryTracking. I'm using OPENJSON but getting compatibility issue. Is there any way to get data without using OPENJSON in sql server 2016? SELECT ( SELECT…
Ritesh Gore
  • 49
  • 10
1
vote
0 answers

Migrating existing maprdb into mongodb. springboot hadoop and maprdb used in the application

' My application used springboot hadoop and maprdb. I never used springhadoop and maprdb before. Please guide. I want to remove maprdb code and connect with mangodb. my code is like this ' public static List<> getData(String a){ List<> DataList =…
user206088
  • 11
  • 2
1
vote
1 answer

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

Question: Why am I unable to apply the OPENJSON function to read the data below into standard columnar form? How can I modify the query or the JSON text to solve this problem? Context: I have some JSON data in a global temp table in SQL Server that…
emalcolmb
  • 1,585
  • 4
  • 18
  • 43
1
vote
3 answers

How to remove .0 from decimal value in FROM OPENJSON( ) WITH in SQL

I want to remove .0 from value of '123.0'. Actually value of $.Item2 is '123.0' .I want to convert it to '123' removing .0 I tried as below but didn't worked SELECT Item1,Item2,Item3 FROM OPENJSON( @DataTable ) WITH (Item1 NVARCHAR(100)…
chandra sekhar
  • 1,093
  • 4
  • 14
  • 27
1
vote
1 answer

Parsing JSON with T-SQL

I'm looking to only select each value name and value in the JSON string and pivot into separate columns in SQL so that I can easily pass these into a powershell string to send to an external API DECLARE @json NVARCHAR(MAX) SET @json='{ …
NickBuckley
  • 77
  • 1
  • 1
  • 9
1
vote
1 answer

SQL Server -- Error = [Microsoft] [SQL Server Native Client 10.0][SQL Server] Invalid object name

Context: a feature of our core application depends on an output file from a stored procedure in SQL Server. The file is supposed to be output via the BCP utility. Question: errors related to an invalid object name seem to be the culprit. The…
emalcolmb
  • 1,585
  • 4
  • 18
  • 43
1
vote
1 answer

Unable to parse string using OPENJSON

I haven't much experience with OPENJSON and I have tried to use the examples but I have been unable to parse the string below Would anybody be able to help me. I would like it to be in the…
MichaelIre
  • 13
  • 3
1
vote
2 answers

Inserting object of two arrays into SQL Database using OPENJSON

I wonder how can I put this JSON object, consisting of two float numbers arrays, into SQL Database Table: { "Latitudes": [ 53.665084, 53.665084, 53.665184, 53.665284 ], "Longitudes":[ 17.342853, 17.342953, …
Kamil Turowski
  • 427
  • 1
  • 4
  • 13
1
vote
1 answer

JSON to SQL Server 2016 missing rows from array

I am new to getting JSON into SQL Server 2016, I thought I had it down, but I notice that I am missing some details from the array, looking at the image, there are four address', but I saw there are some more address' missing for example Burrows Rd,…
DrDuran
  • 101
  • 1
  • 3
  • 12
1
vote
1 answer

How can i do a join with a GEOJson file and a table that exists already in the database?

I have a file with GEOJson data like so: { "type": "FeatureCollection", "features": [ { "type": "Feature", "geometry": { "type": "Polygon", "coordinates": [ [ [-73.759739, 42.61379], …
MrTouya
  • 656
  • 6
  • 19
1
vote
1 answer

OpenJson in SQL Server for nested json data?

I have a json data like this: [ {"id": 1}, {"id": 3}, {"id": 2, "children": [{"id": 4}, {"id": 5}]} ] Please help me how to parse this data into relational data: Column: Id Order/Index ParentId --------------------------------------- …
user3836200
  • 111
  • 1
  • 13
0
votes
2 answers

How to get @odata.etag value from JSON in SQL Server table

Does anybody knows how to get @odata.etag value from a JSON into a SQL Server table? Many thanks! JSON string: { "@odata.context": "https://mycompany.com/Tenant/ODataV4/$metadata#Company('mycompany')/ServiceHeader/$entity", …