We have grids that we have custom filters for and you can save the filters as a JSON object to a particular table, tblUserPersistedValue (along with a user field).
So we are updating the page and the filters are going from single-select IDs to multi-select IDs on four different filters.
Curent JSON:
'{
"ProductGroupID":1,
"TerminalID":1,
"CarrierID":1221,
"RegionID":21,
"DriverDateFilter":0,
"DriverStartDate":"0001-01-01T00:00:00",
"DriverEndDate":"0001-01-01T00:00:00"
}';
Where You see "TerminalID":1, I would like to change it to "TerminalID":[1]
so we don't break any user's settings when we make the update.
Unfortunately i am unable to figure out how to create an int array with JSON_MODIFY.
I am almost there, but it's wrapping the value i'm saving in quotes, and that won't parse into an int array during deserialization.
I have never worked with json directly in sql before and I must be missing something simple. How do i fix it? If it's impossible to overwrite the existing entry, I could also make a new TerminalIDs entry to parse into and remove the old one.
The ultimate goal is to do this for every record in the table, once for each of four fields.
JSONfunctions and without string manipulations -SELECT @json = JSON_MODIFY(@json, '$.TerminalID', JSON_MODIFY(N'[]', 'append $', CONVERT(int, JSON_VALUE(@json, '$.TerminalID')))).