RepositoryRustNLNetherlands
alurm

alurm/json2dir

Directory archives, made human-readable

143stars
7forks
5issues
2views

Featured achievements

The project's latest awards

1
TINIX TRENDING·Topic: configuration-management

#1 Repository of the month

1
TINIX TRENDING·Topic: extractor

#1 Repository of the month

2
TINIX TRENDING·Topic: json

#2 Repository of the month

json2dir: directory archives, made human-readable

Build status 100% region coverage

json2dir it a tool suitable for converting JSON objects into directory trees using a special conversion scheme specified below.

Table of contents

TL;DR

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.

Use cases

Since json2dir accepts any JSON, it has a variety of use cases with other tools that can generate JSON.

Managing dotfiles with Nix

json2dir can be used together with nix profile as a home-manager replacement for managing dotfiles. Explanation.

Conversion scheme

Objects

Objects represent directories. Keys of objects represent names of files in directories. The JSON document as a whole must be an object.

Examples

An empty directory: {}.

A directory with an empty directory named foo: {"foo": {}}.

Strings

String values represent contents of files.

Examples

A directory with a file named hello with the text Hello, world: {"hello": "Hello, world"}.

Arrays

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.

Examples

A symbolic link pointing to the root directory: ["link", "/"].

An executable file printing Hello when ran: ["script", "#!/bin/sh\necho Hello"].

Design considerations

  • UTF-8: regular JSON constraints apply. In particular, unicode strings are interpreted as UTF-8. Currently, there's no way to represent files containing non-UTF-8 content.
  • Time of check, time of use attacks: when using this utility to create files for other users, care must be taken in order to prevent TOCTOU (time of check, time of use) attacks (e.g. with symlinks). json2dir makes no attempt to guard against such attacks.
  • Deletion: json2dir tries to delete a file or a directory before overwriting it.
  • String paths with multiple segments: currently rejected, nested objects should be used instead.
  • String paths with special segments: rejected. This is a basic measure to prevent rooted paths, therefore all paths must be relative.

Installing

json2dir can be installed in multiple ways.

With Cargo

Run cargo install json2dir.

With Nix

Run nix profile add github:alurm/json2dir.

Development

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.

Similar Projects

Discover other similar projects and AI models.

RepositoryRust
biomejs/biome

A toolchain for web projects, aimed to provide functionalities to maintain them. Biome offers formatter and linter, usable via CLI and LSP.

26.3k
Dec 2, 2026
RepositoryRust
rust-cli/config-rs

⚙️ Layered configuration system for Rust applications (with strong support for 12-factor applications).

3.2k
Nov 20, 2026
RepositoryRust
habitat-sh/habitat

Modern applications with built-in automation

2.8k
Nov 25, 2026
RepositoryRust
comtrya/comtrya

Configuration Management for Localhost / dotfiles

609
Nov 27, 2026
RepositoryRust
gengteng/axum-valid

axum-valid is a library that provides data validation extractors for the Axum web framework. It integrates validator, garde and validify, three popular validation crates in the Rust ecosystem, to offer convenient validation and data handling extractors for Axum applications.

167
Jun 30, 2026
RepositoryRust
rolanfreeman6-png/RenpyEx

Pure-Rust Ren'Py archive extractor. Byte-perfect .rpa and .rpyc unpacking, auto key detection from options.rpy, SHA-256 integrity verification, strict (lossless) output. Goal: every extracted byte equals source byte.

89
Aug 19, 2026
RepositoryPython
fastapi/fastapi

FastAPI framework, high performance, easy to learn, fast to code, ready for production

105.2k
Dec 3, 2026
RepositoryJavaScript
chinese-poetry/chinese-poetry

The most comprehensive database of Chinese poetry 🧶最全中华古诗词数据库, 唐宋两朝近一万四千古诗人, 接近5.5万首唐诗加26万宋诗. 两宋时期1564位词人,21050首词。

54.6k
Jun 17, 2026
RepositoryC++
nlohmann/json

JSON for Modern C++

51.1k
Dec 2, 2026