I have a query that takes an array of a explicit number of (let's say 100) arrays of a sequence of values. the json looks something like this
[["horse",6],
...,
["dog",100]]
Each of these array elements maps directly to some other table. While I can do the following to do the update, I'd prefer to be able to use an explicit schema.
update some_table
set favorite_animal=convert(varchar(50),json_value(value,'strict $[0]'))
,favorite_number=convert(int,json_value(value,'strict $[1]'))
from openjson(@json)
where id = convert(int,[key])
Unfortunately, when I use an explicit schema, I'm not sure how to specify the current path (the value in [key]
).
I'd really like if I could do something like this but I can't find the syntax:
from openjson(@json)
with (favAnimal varchar(50) '$[0]',favNumber int '$[1]', row int '[key]')