I try to get data from JSON with stored procedures and I have data in JSON format.
This is my data:
{
"data": [
{
"@attributes": {
"id": "123456",
"name": "test"
}
},
{
"prices": {
"price": [
{
"@attributes": [
{
"date": "2019-06-13",
"price": "600",
"currency": "$"
},
{
"date": "2019-06-15",
"price": "700",
"currency": "$"
}
]
}
]
}
},
{
"images": {
"image": [
{
"@attributes": [
{
"date": "2019-06-13",
"url": "xxxxx"
}
]
}
]
}
}
]
}
and I try will get data price in JSON by get "id": "123456" is PK of price
This my stored procedure:
INSERT @price_tmp (id, date, price, currency)
SELECT id, date, price, currency
FROM OPENJSON(@InputJson,'$.data.prices.price')
WITH (
id nvarchar(50) '../../$."@attributes".id',
price_date nvarchar(255) '$."@attributes".date',
price_price nvarchar(50) '$."@attributes".price',
price_currency nvarchar(255) '$."@attributes".currency'
) AS jsonValues`
after I do
select * from @price_tmp;
I expect to see data like this:
ID | date | price | currency
-------+------------+---------+---------
123456 | 2019-06-13 | 600 | $
123456 | 2019-06-15 | 700 | $
But it does not show anything
I can use Answer both
Thank you metal and Zhorov