My flow is to go through the Pandoc JSON AST and then use Jq. This works for other input formats, too.
I've never had a need for parsing markdown like this, bit I have to wonder, would it make to go through HTML instead, given that it's what markdown is designed to compile to? At that point, I'd assume there's any number of existing XML tools that work work, and my (maybe naive) assumption is that typical markdown documents would be relatively flat compared to how deeply nested "native" HTML/XML often gets, so it does…
markdown -> xhtml -> sxml -> logic (racket)