Castelli was born in Buenos Aires in 1764. He was the first of eight children born to a Venetian doctor, Ángel Castelli Salomón, and Josefa Villarino, who was a relative of Manuel Belgrano. He was trained by the Jesuits shortly before their expulsion, and attended the Real Colegio de San Carlos in Buenos Aires. As was customary, one of the children of the Castelli family was ordained into the priesthood, and Juan José was chosen for this. He was sent to study at the Colegio Monserrat, part of the University of Córdoba. He was influenced by the works of Voltaire and Diderot, and especially by Jean-Jacques Rousseau's "The Social Contract". He was a fellow student of men who would later have influence in the public life of South America, including Saturnino Rodríguez Peña, Juan José Paso, Manuel Alberti, Pedro Medrano, and Juan Martínez de Rozas, among others. He focused on studying philosophy and theology, but when his father died in 1785, he abandoned his career in the priesthood, for which he felt no strong vocation.