Andersen 's tale is based on a story from the `` Libro de los ejemplos '' ( or `` El Conde Lucanor '' , 1335 ) , a medieval Spanish collection of fifty-one cautionary tales with various sources such as Aesop and other classical writers and Persian folktales , by Juan Manuel , Prince of Villena ( 1282 -- 1348 ) .
The story is based on one from the `` Libro de los ejemplos del conde Lucanor y de Patronio | Libro de los ejemplos '' ( or `` El Conde Lucanor '' , 1335 ) by Juan Manuel , Prince of Villena ( 1282 -- 1348 ) . This book was a medieval Spanish collection of fifty-one cautionary tales with various sources such as Aesop and other classical writers and Persian folktales .