Implement JSON export.

This is a fully functional export, based on a customized array_merge_recursive.