Convert JSON to SQL Format

Carlton Patterson 741 Reputation points
2022-02-03T13:22:50.907+00:00

Hello Community,

I have the attached JSON Code. I would like to be able recode the JSON so as to able to work with the code in SQL.

When you look at the file, you will see that it is very large, so I apologise in advance. However, if someone could either help convert the code, or put on the path to be able to do it myself I would be most grateful.

Thanks171006-json-code.txt

Developer technologies Transact-SQL
{count} votes

Accepted answer
  1. Yitzhak Khabinsky 26,586 Reputation points
    2022-02-03T16:51:17.023+00:00

    Hi @Carlton Patterson ,

    Please try the following solution.
    It will give you a good jump start.

    SQL

    SELECT report.*  
    FROM OPENROWSET(BULK N'e:\Temp\json-code.json', SINGLE_CLOB) AS j  
    CROSS APPLY  
    OPENJSON(BulkColumn, N'$.mappings[0].ELLIPSE.columns')  
    WITH   
    (  
        [column]		VARCHAR(100)	'$.column'  
        , [type]		VARCHAR(20)		'$.type'  
        , [length]		INT				'$.length'  
        , [allowNulls]	VARCHAR(5)		'$.allowNulls'   
        , [transform]	VARCHAR(200)	'$.transform'  
        , [mapType]		VARCHAR(20)		'$.mapType'  
        , [source]		NVARCHAR(MAX) AS JSON  
    ) AS report;  
    
    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Carlton Patterson 741 Reputation points
    2022-02-03T16:59:18.09+00:00

    YitzhakKhabinsky-0887

    I have the tables and columns that I would like to extract, see attached. Ideally, I would like the tables to extracted as individual CSVs.

    This request might need someone experienced with Excel - as I can't imagine someone actually copying and pasting the tables and columns into individual csv tables. For example, there is a table called AZ_FND_MSF010, which has multiple columns with each column having its own attributes e.g. DataType. I would need tables and column(with attributes) extracted into a single CSV's

    Is that something you (or anyone in the community)171085-newtable.txt could help me with?

    0 comments No comments

  2. CathyJi-MSFT 22,396 Reputation points Microsoft External Staff
    2022-02-04T08:35:08.943+00:00

    Hi @Carlton Patterson ,

    > Ideally, I would like the tables to extracted as individual CSVs.

    You can use SSMS Import and Export Wizard to export SQL server data to .CSV. Refer to this blog to get more.

    Please also check this blog to get other methods to import SQL data to Excel.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    0 comments No comments

Your answer

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