YAML Command Line Interface (CLI)
raw JSON →yaml-cli is a command-line interface tool designed for directly interacting with YAML files, providing functionalities such as querying values, setting properties, instantiating templates, and converting between YAML and JSON formats. Currently at version 1.1.8, this project has been officially deprecated. While it offers a simple and direct approach to YAML manipulation via shell commands, its developers now recommend using `yq` as a more actively maintained and feature-rich alternative. Key differentiators of yaml-cli include its intuitive dot-notation for nested property access and array indexing, and its built-in templating engine. Users should be aware of its deprecated status and consider migrating to `yq` for new projects or ongoing maintenance to ensure continued support and access to new features.
Common errors
error yaml: command not found ↓
npm install -g yaml-cli or ensure that the npm global bin directory is included in your system's PATH environment variable. error (<unknown>): mapping values are not allowed in this context at line X column Y ↓
: or spaces in a key, or yes/no/true/false values that should be strings), enclose it in single or double quotes. Warnings
breaking This `yaml-cli` project (pandastrike/yaml-cli) has been officially deprecated by its maintainers. It is no longer under active development and new features or bug fixes should not be expected. Users are strongly encouraged to migrate to `yq` (https://github.com/mikefarah/yq) for robust and actively maintained YAML processing functionality. ↓
gotcha YAML files are highly sensitive to indentation. Using tabs instead of spaces, or inconsistent spacing, will lead to parsing errors and unexpected behavior, often resulting in obscure error messages or malformed output. ↓
gotcha Values in YAML files can be interpreted differently based on their content (e.g., 'true' might be a boolean, '7' an integer). Strings containing special characters or what might look like boolean/numeric values (e.g., 'no', 'on', '0.1') should be explicitly quoted to ensure they are parsed as strings. ↓
Install
npm install yaml-cli yarn add yaml-cli pnpm add yaml-cli Quickstart
# Install the CLI globally
npm install -g yaml-cli
# Create a sample YAML file
cat << EOF > mydata.yaml
user:
name: Alice
settings:
theme: dark
notifications: true
items:
- id: 1
name: Item A
- id: 2
name: Item B
EOF
echo "Original YAML:"
cat mydata.yaml
echo "\n"
# Get a value
echo "Getting user name:"
yaml get mydata.yaml user.name
echo "\n"
# Set a value
echo "Setting user theme to light:"
yaml set mydata.yaml user.settings.theme light
echo "\n"
echo "Updated YAML:"
cat mydata.yaml
echo "\n"
# Convert to JSON
echo "Converting to JSON:"
yaml json write mydata.yaml