I am trying to Import the Currency Data into a table.
I am able to import one of the data objects by specifying FROM OPENJSON (@JSON, '$.currency."0"') however I am struggling to find a solution which helps me gather all 5 currencies into there own column.
I want to use the unique JSON Object headers for each currency as a data Item (DefaultCurrencyCode)
This is the JSON Data:
"currency": {
"0": {
"ISOCode": "USD",
"name": "US Dollar",
"symbol": "$",
},
"1": {
"ISOCode": "IEP",
"name": "Irish Pound or Punt",
"symbol": "£",
},
"2": {
"ISOCode": "BEF",
"name": "Belgian Franc",
"symbol": "₣",
},
"3": {
"ISOCode": "ZAR",
"name": "South African Rand",
"symbol": "R",
},
"4": {
"ISOCode": "JPY",
"name": "Japanese Yen",
"symbol": "¥",
}
}
This is my SQL Server code:
DECLARE @JSON VARCHAR(MAX)
SELECT @JSON = BulkColumn
FROM OPENROWSET
(BULK 'C:\dev\src\Client\config\common\config.json', SINGLE_CLOB)
AS j
SELECT ISOCode, name, symbol ,DefaultCurrencyCode
INTO TestTable2
FROM OPENJSON (@JSON, '$.currency."0"')
WITH (
ISOCode VARCHAR(10),
name VARCHAR(50),
symbol VARCHAR(50),
DefaultCurrencyCode INT)
Select * From TestTable2
This is my current output, however I am trying to get all of them.

, '$.currency."0"'in the open and format the columns in theWITHsection.