Recently, there is rapid integration of power electronic converter (PECs) into the power grid. Most of these PECs are grid-following inverters, where weak grid operation becomes an issue. Research is now shifting focus to grid-forming (GFM) inverters, resembling synchronous generators. The shift towards converter-based generation necessitates accurate PEC models for assessing system dynamics that were previously ignored in conventional power systems. Data-driven modeling (DDM) techniques are becoming valuable tools for capturing the dynamic behavior of advanced control strategies for PECs. This paper proposes using power hardware-in-the-loop experiments to capture dynamic GFM data in the application of DDM techniques. Furthermore, the paper derives an analytical approach to obtaining a mathematical model of GFM inverter dynamics and compares it with the DDM. A square-chirp probing signal was employed to perturb the active and reactive power of the load inside an Opal-RT model. The dynamic response of the GFM inverter, including changes in frequency and voltage, was recorded. This data was then used in a system identification algorithm to derive the GFM DDMs. The effectiveness of DDM is cross-validated with an analytical approach through experimental simulation studies, and the goodness-of-fit for both approaches is compared. Both approaches show more than 85% accuracy in capturing the dynamic response of GFM inverters under different loading conditions.INDEX TERMS Data-driven modeling, grid-forming inverter, power hardware-in-the-loop, power system dynamics, real-time digital simulator, system identification.