Sort the tasks according to their order when generating JSON.

Addresses #21, #22.