Niet: YAML, JSON, TOML CLI Tool
Niet is a powerful command-line interface (CLI) tool designed for efficient interaction with YAML, JSON, and TOML data files. It allows users to slice, filter, map, transform, and convert structured data using simple expressions or advanced XPath features directly from the shell. Written in Python, `niet` is actively maintained, with its latest version 3.2.0 released in April 2023.
Common errors
-
niet: command not found
cause The `niet` executable is not in your system's PATH, or the package was not installed correctly.fixEnsure `niet` is installed (`pip install niet`) and that your shell's PATH includes the directory where `pip` installs executables (e.g., `~/.local/bin` on Linux or `Scripts` directory in your Python environment on Windows). You might need to restart your terminal. -
ERROR: [Errno 2] No such file or directory: 'non_existent_file.yaml'
cause The input file specified for `niet` does not exist at the given path.fixVerify the file path and name are correct. Use `ls` or `dir` to confirm the file's presence. -
ERROR: Unable to parse file, check the format: "Invalid YAML syntax"
cause The input file (YAML, JSON, or TOML) contains syntax errors and cannot be parsed by `niet`. `niet` exits with a non-zero status code (e.g., 1) in such cases.fixInspect the input file for syntax errors using a linter or validator for YAML, JSON, or TOML. Ensure it conforms to the expected format.
Warnings
- breaking Python 2.7 support was dropped in `niet` version 2.0. If you require Python 2.7, you must use a version of `niet` lower than 2.0.
- gotcha `niet` is primarily a command-line interface tool and is not designed for direct programmatic import and use within Python scripts like a typical library. All core functionalities are exposed via its CLI.
- gotcha Using the `-i` or `--in-place` argument will modify the input file directly, replacing its content with the `niet` command's output. This can lead to unintended data loss if not used carefully or without backups.
Install
-
pip install niet
Quickstart
echo "---\nproject:\n meta:\n name: my-app\n version: 1.0.0" > config.yaml
niet config.yaml "project.meta.name"
# Expected output: my-app
echo '{"data": {"items": [{"id": 1, "value": "alpha"}, {"id": 2, "value": "beta"}]}}' > data.json
niet data.json "data.items[?id=2].value"
# Expected output: beta