Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,689 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi everyone.
Thanks for looking at my issue.
DECLARE @j nvarchar(max) =
'{
"version": "1.0",
"content": [
{},
{
"dataField": "Queue",
"name": "Queue",
"editorType": "dxTextBox",
"visibleIndex": 2,
"colSpan": 2,
"editorOptions": {
"placeholder": "MSMQ Queue"
},
"groupItemOptions": {
"name": "output"
}
}
]
}'
DECLARE @key_content int = 1
DECLARE @placeholder nvarchar(max) = JSON_VALUE(@j, CONCAT('lax $.content', QUOTENAME(@key_content), '.editorOptions.placeholder'))
SET @placeholder = CONCAT('{"text":"', @placeholder, '"}')
SET @j = JSON_MODIFY
(
@j
,CONCAT('append $.content', QUOTENAME(@key_content), '.label')
,JSON_QUERY(@placeholder)
)
SELECT @j as [@j], JSON_VALUE(@j, CONCAT('lax $.content', QUOTENAME(@key_content), '.label.text')) as placeholder
I am getting an array
,"label":[{"text":"MSMQ Queue"}]}
but want an object
,"label":{"text":"MSMQ Queue"}}
Why JSON_QUERY adds []?
What am I missing here?
Thanks
Vladimir
Please try the following:
SET @j = JSON_MODIFY
(
@j
,CONCAT('$.content', QUOTENAME(@key_content), '.label')
,JSON_QUERY(@placeholder)
);