Controlled mixtures of novel Mg-based metal-organic frameworks (MOFs) were prepared, with H+ or K+ as counterions. A linear relation was found between synthesis pH and K/H ratio in the resultant mixture, establishing the tunability of the synthesis. Upon pyrolysis, these precursor mixtures yield nitrogendoped, hierarchically porous carbons, which have good activity towards the oxygen reduction reaction (ORR) at pH 13. The nitrogen content varies significantly along the homologous carbon series (>400%, 1.3 at% to 5.7 at%), to a much greater extent than microstructural parameters such as surface area and graphitization. This allows us to isolate the positive correlation between nitrogen content and electrocatalytic oxygen reduction ORR activity in this class of metal-free, N-doped, porous carbons.