Tidy up and modularise nimrodel to json code.

In principle, the brat code could be refactored slightly
to use the helper functions introduced in literal