I'm working on a project in which I need the ability to receive and consume (i.e. extract information) from received JSONs. The current version of SQL Server I am using (and will not change for the next couple of years) is 2012, which does not include support for this (as opposed to version 2016).
I do recall seeing a post from someone in which he gently offered a source code for this, but unfortunately can't find it again.
The idea is to have something like:
Having the following JSON:
{
"Obj1": {
"Obj1_S_1": [{
"Obj1_S_1_S_1": "Blabla_1"
}, {
"Obj1_S_1_S_1": "Blabla_2"
}, {
"Obj1_S_1_S_1": "Blabla_3"
}, {
"Obj1_S_1_S_1": "Blabla_4"
}, {
"Obj1_S_1_S_1": "Blabla_5"
}, {
"Obj1_S_1_S_1": "Blabla_6"
}]
},
"Obj2": "This is a simple string",
"Obj3": "456.33"
}
I could use the following invocation:
SET @My_Param = GET_JSON(@Source_JSON, '*.Obj1.Obj1_S_1[3].Obj1_S_1_S_1') ;
and I would get the value 'Blabla_4'
into the variable @My_Param
.
This is the very same syntax used in Oracle and MySQL by the way.