json2dir: directory archives, made human-readable
json2dir it a tool suitable for converting JSON objects into directory trees using a special conversion scheme specified below.
Let's start with an example.
Assume the we have the file named example-tree.json in the current directory with the following contents:
{
"greeting": "Hello, world!",
"dir": {
"subfile": "Content.\n",
"subdir": {}
},
"symlink": ["link", "target path"],
"script": ["script", "#!/bin/sh\necho Howdy!"]
}
And then, after installing json2dir, we run this command:
cat example-tree.json | json2dir
Here, four files will be added to the current directory:
greeting: a regular file containing the text Hello, world!.dir: a directory with two entries in it (subfile and subdir).symlink: a symbolic link pointing to target path.script: an executable shell script that prints Howdy! when run.Learn the conversion scheme for more details.
Since json2dir accepts any JSON, it has a variety of use cases with other tools that can generate JSON.
json2dir can be used together with nix profile as a home-manager replacement for managing dotfiles. Explanation.
Objects represent directories. Keys of objects represent names of files in directories. The JSON document as a whole must be an object.
An empty directory: {}.
A directory with an empty directory named foo: {"foo": {}}.
String values represent contents of files.
A directory with a file named hello with the text Hello, world: {"hello": "Hello, world"}.
Arrays represent symlinks and files with an executable bit set (executable files, scripts). Such files are not supported on Windows.
The first element of the array must be a string.
If the string is "link", the second array element represents the target of the symlink.
If the string is "script", the second array element represent the contents of the executable file.
A symbolic link pointing to the root directory: ["link", "/"].
An executable file printing Hello when ran: ["script", "#!/bin/sh\necho Hello"].
json2dir makes no attempt to guard against such attacks.json2dir tries to delete a file or a directory before overwriting it.json2dir can be installed in multiple ways.
Run cargo install json2dir.
Run nix profile add github:alurm/json2dir.
To build the project, run cargo build or nix build. If you're using rustup, rust-toolchain.toml is provided.
Useful scripts may be found in the scripts folder.
Feel free to fork the project, open issues, submit PRs.
$ claude mcp add json2dir \
-- python -m otcore.mcp_server <graph>