This is a replacement/extension of #4949, which also adds code for automatically generating the json tests.
The test generation is always executed (to prevent bitrot), and verified as if it was read from the json file itself (to make sure it remains consistent with the code), but not written out by default.
The reason for actually bothering to still have code to convert these to JSON is because the JSON tests are also used by other implementations.