@Martin you could have extended that into an answer. I realize I missed the with option I have after the openjson as that would have eliminated the need for json_value in the projection.
I struggle a lot with pivot. I never seem to be able to get the syntax right on the first try and always have to refer back to my simple example. And when I have overcome the syntax errors, the results are not correct. Either it groups on the wrong field or it doesn't like the aggregate function I use. It is not intuitive at all.
I might be spoiled by MS Access that does have a pivot statement but it can take rows from a table as column headers. So it is totally dynamic. Not the case in SQL Server.