Add JSON output and tests.