September 24, 2021 at 12:00 am
Comments posted to this topic are about the item The OPENJSON return schema
September 24, 2021 at 8:27 am
I've not used this functionality, but the spec. doesn't say to me what the topic suggests:
September 24, 2021 at 2:51 pm
This comment alludes to the expected correct answer so I put it in a spoiler block.
DECLARE @j_data NVARCHAR(max) = '[
{
"row_id": 1,
"row_text_value": "This is my text",
"row_date_value": "2021-09-21T08:31:48"
}, {
"row_id": 2,
"row_text_value": "This is my other text",
"row_date_value": "2021-08-07T18:29:13"
}
]'
SELECT * FROM openjson(@j_data) WITH (
row_id INT,
row_text_value VARCHAR(128),
row_date_value DATETIME2
)
The documentation reads:
with_clause contains a list of columns with their types for OPENJSON to return. By default, OPENJSON matches keys in jsonExpression with the column names in with_clause (in this case, matches keys implies that it is case sensitive). If a column name does not match a key name, you can provide an optional column_path, which is a JSON Path Expression that references a key within the jsonExpression
-
September 24, 2021 at 2:59 pm
But the quoted text from the docs doesn't say anywhere that a name, data type, and JSON path are required, merely that with_clause contains a list of columns with their types. It later says you can provide an optional column path, which is a JSON Path expression, but it's optional.
September 24, 2021 at 3:57 pm
Good catch. I misread the help. I've updated the answers and explanation.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply