This would probably read more cleanly if we constructed a map and then used the json package to serialize it instead of doing string manipulation. Not sure what the performance impact would be, though, probably not worth it if it's a lot slower.