cost of a lesson learned; price of a life lesson
Colloquial expression for the price paid (money, time, or trouble) for a valuable lesson, often from a mistake or failure.
詐欺に遭って大金を失ったけど、いい勉強代になったと思う。
I lost a lot of money in a scam, but I think it was a good price for a life lesson.
失敗は勉強代だと思って、次に活かそう。
Think of failure as the cost of learning, and use it for next time.
Compound of 勉強 (study, learning) and 代 (cost, price). The figurative sense likely developed from the idea of paying for one's education through real-world experience.