All of the examples examples I see dealing with json arrays have the array nested under a top level object. I have a json array in a column:
[{"key": "value1"}, {"key": "value2"}]
I would like to run a sql script to add/update a key for each element in the array, resulting in:
[{"key": "value1", "otherKey": "otherValue"}, {"key": "value", "otherKey": "otherValue"}]
Yes, in my case I want the same value set for each array member. I've tried:
declare @info nvarchar(max)
SET @info = '[{"key": "value1"}, {"key": "value2"}]'
print JSON_MODIFY(@info, '[0].otherKey', '""')
and fails with "JSON path is not properly formatted. Unexpected character '[' is found at position 0."
This is in MSSQL 2017.