Correct term for a person working two jobs secretly
The correct term for this is moonlighting, which means:
Have a second job in addition to one’s regular employment.
It often carries a connotation of secrecy. The second job is done under metaphorical moonlight. Cambridge captures this connotation:
paid work that you do in addition to your normal job, especially without telling your employer.
It fits perfectly into your example context:
"John's employer found out that he is moonlighting for other companies. Now he's in serious trouble."
Here is the etymology according to Etymonline.com:
moonlight (v.)
"hold a second job, especially at night," 1957 (implied in moonlighting), from moonlighter (1954), from the notion of working by the light of the moon; see moonlight (n.). Related: Moonlighting. Earlier the word had been used to mean "commit crimes at night" (1882).
I think the moonlighting answer is correct, but in the interest of throwing another word into the mix: you could say that the person is freelancing:
working for different companies at different times rather than being permanently employed by one company.
"a freelance journalist"
synonyms: self-employed, independent, contract
"John's main employer found out that he is freelancing for other companies during his off-time. He is now in serious trouble."