Agent skill
json-config-loader-6-yaml-configuration-via-yq
Sub-skill of json-config-loader: 6. YAML Configuration (via yq).
Install this agent skill to your Project
npx add-skill https://github.com/vamseeachanta/workspace-hub/tree/main/.claude/skills/_core/bash/json-config-loader/6-yaml-configuration-via-yq
SKILL.md
6. YAML Configuration (via yq)
6. YAML Configuration (via yq)
Parse YAML files when yq is available:
#!/bin/bash
# ABOUTME: YAML configuration parsing with yq
# ABOUTME: Falls back to jq for JSON subset of YAML
# Check for yaml parser
get_yaml_parser() {
if command -v yq &> /dev/null; then
echo "yq"
elif command -v jq &> /dev/null; then
echo "jq" # Can parse YAML's JSON subset
else
echo "none"
fi
}
# Load YAML config
load_yaml_config() {
local file="$1"
local parser
parser=$(get_yaml_parser)
if [[ ! -f "$file" ]]; then
echo "{}"
return 1
fi
case "$parser" in
yq)
yq -o=json "$file" 2>/dev/null || echo "{}"
;;
jq)
# Try to parse as JSON (YAML subset)
jq '.' "$file" 2>/dev/null || echo "{}"
;;
*)
echo "Error: No YAML parser available (install yq or jq)" >&2
echo "{}"
return 1
;;
esac
}
# Get YAML value (returns as JSON for jq processing)
yaml_get() {
local file="$1"
local path="$2"
local default="${3:-}"
local parser
parser=$(get_yaml_parser)
local value
case "$parser" in
yq)
value=$(yq -r "$path // \"$default\"" "$file" 2>/dev/null)
;;
jq)
value=$(jq -r "$path // \"$default\"" "$file" 2>/dev/null)
;;
*)
value="$default"
;;
esac
if [[ -z "$value" || "$value" == "null" ]]; then
echo "$default"
else
echo "$value"
fi
}
# Usage
CONFIG_FILE="config.yaml"
# Load entire config as JSON
CONFIG_JSON=$(load_yaml_config "$CONFIG_FILE")
# Or get specific values
DB_HOST=$(yaml_get "$CONFIG_FILE" '.database.host' 'localhost')
DB_PORT=$(yaml_get "$CONFIG_FILE" '.database.port' '5432')
echo "Database: $DB_HOST:$DB_PORT"
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
gsd-complete-milestone
Archive completed milestone and prepare for next version
gsd-reapply-patches
Reapply local modifications after a GSD update
gsd-verify-work
Validate built features through conversational UAT
gsd-thread
Manage persistent context threads for cross-session work
clinical-trial-protocol
Generate clinical trial protocols for medical devices or drugs through a modular, waypoint-based architecture with research-only and full protocol modes.
single-cell-rna-qc
Performs quality control on single-cell RNA-seq data (.h5ad or .h5 files) using scverse best practices with MAD-based filtering and comprehensive visualizations.
Didn't find tool you were looking for?