The first part of this story is given in the Hitōpadesa, but not the trial before the Monkey King.

No. 39

The Jackal Dēvatāwā

In a certain country there was a dead Elephant, it is said. A Jackal having gone to eat the Elephant’s carcase, and having eaten and eaten a hole into the Elephant from behind, passed inside it. While he was eating and eating the carcase of the Elephant as he remained inside it, the skin [dried and] became twisted up, and the path by which the Jackal entered became closed.

A man who was a tom-tom beater was going near it, taking a tom-tom for a devil-dance. Then among the bones the sound of tom-tom beating was heard. So the Jackal asked, “Who is going here?”

The tom-tom beater said, “I am going to this devil-dance.”

The Jackal said, “What art thou going this way for, without permission?”

The tom-tom beater replied, “O Lord, I am going without knowing about this [permission’s being necessary].”