I too was the middle kid. Here's my own anecdotal advice:
I started slacking in school from about 3rd-9th grade.
I found programming between 9th-10th grade during the summer through pretty much sheer dumb luck, timing, and being in the perfect environment.
After that, my grades improved, confidence improved, everything improved.
The school system may not be able to offer your kid the opportunity they need to really find the inspiration that can kick them into drive.
Maybe try to expose them to as many things as you can, and see what clicks?
Another thing is how they learn.
I learned through modding video games and could see instant results, via changing just a few variables, of what programming could do, and would share these with my friends.
This instant gratification and social "confirmation" from my friends, as well as the communities I joined, really pushed me forward. Plus, I really enjoyed it.
Shortly after modding video games, I tried getting into creating websites but didn't quite see the instant gratification or have the social "confirmation" to push me as hard as I did with modding video games.
Yeah, that's definitely a good way to do it as long as the kid doesn't feel like they're being forced.
It's sorta tough though with them choosing because if I was in 9th grade again and had the option, I don't know if I'd choose a programming curriculum.
It reminds me of the Steve Jobs quote, "People don't know what they want until you show it to them."
My middle kid is enjoying competitive chess and doing math through Art of Problem Solving, so there's places he does work hard and there is intellectual challenge. And his slacking is good enough to be at the top of his class, so I can't quibble too much.
I'm sure there'll be problems eventually, but, we're ready and up until then we're trying...
The flip-side is, social adaptation/easy-going-ness actually makes it easier for his teachers to challenge him, etc.
The oldest reminds me of me, struggles and all. I have to think my middle kid has an easier path of things than I did.