I have a table with json vaules in nvarchar columns
ID ConfigKey ConfigValue
1 employee {"name":"jhon","age":"23","salary":"5000"}
2 Dept {"name": "Marketing", "code":"12", "manager":"sam"}
3 manager {"managername":"abc", "dept":"AB"}
I need to get merged json for selected ConfiKey by adding ConfigKey value as node name for the ConfigValue and also merged json as below.
For example when i want to get for employee and manager. Output should be like
{
"employee": {
"name": "jhon",
"age": "23",
"salary": "5000"
},
"manager": {
"managername": "abc",
"dept": "AB"
}
}
When I want to get for only ConfigKey value employee output should be
{
"employee": {
"name": "jhon",
"age": "23",
"salary": "5000"
}
}
I tried using JSON_MODIFY but couldn't achieve this. How I can achieve this in SQL query.