This is some code that may be useful to dump to json:
I’ve found json to be less troublesome than CSV in several cases.