The current implementation of the JSONWriter does not support writing out directory entries. Earlier today I added a unit test to illustrate the problem. When an entry is added to the YAMLVFSWriter and the path is a directory, it will incorrectly emit the directory as a file, and any files inside that directory will not be found by the VFS.
Usually it's possible to work around the issue by only adding leaf nodes (files) to the YAMLVFSWriter. However, this doesn't work for representing empty directories. This is a real issue for clients of the VFS that want to iterate over a directory. The directory not being there is not the same as the directory being empty.
This is not just a hypothetical problem but a real issue. The FileCollector does not differentiate between file and directory paths. I temporarily worked around the issue for LLDB by ignoring directories, but I suspect this will prove problematic sooner rather than later.
This patch fixes the issue by extending the JSONWriter to support writing out directory entries. We have to special-case the first entry, but otherwise it's just a matter of emitting a directory entry instead of a file entry.