Convert a directory structure to json representation