Share via

Reading Json File

RAVITEJA DUDDU 21 Reputation points
2021-01-27T07:30:02.94+00:00

--Here I use the below script to read the .json file But finally, i have got the result jobTitle with data as null

DECLARE @json VARCHAR(MAX)

SELECT @json = BulkColumn
FROM OPENROWSET(BULK 'D:\DBBBACKUP\Jobtitle.json', SINGLE_cLOB) AS j

SELECT @json

SELECT ISJSON(@json )

---Here file size is 320kb

SELECT Jobtitle
FROM OPENJSON(@json ) WITH (Jobtitle VARCHAR(MAX) '$.Jobtitle')

SQL Server | Other
SQL Server | Other

Additional SQL Server features and topics not covered by specific categories


1 answer

Sort by: Most helpful
  1. Cris Zhan-MSFT 6,676 Reputation points
    2021-01-27T10:12:29.913+00:00

    Hi,

    >SELECT Jobtitle FROM OPENJSON(@json ) WITH (Jobtitle VARCHAR(MAX) '$.Jobtitle')

    The '$.Jobtitle' is the problem, the Jobtitle key may not exist, or there may be an sequence problem. It is difficult to judge without looking at your json file.

    It is recommended that you check the following documents to learn more about OPENJSON.
    https://learn.microsoft.com/en-us/sql/t-sql/functions/openjson-transact-sql?view=sql-server-ver15
    https://learn.microsoft.com/en-us/sql/relational-databases/json/json-data-sql-server?view=sql-server-ver15#convert-json-collections-to-a-rowset

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.