json-config-loader-1-keyvalue-configuration-parsing

Sub-skill of json-config-loader: 1. Key=Value Configuration Parsing (+1).

5 stars

Best use case

json-config-loader-1-keyvalue-configuration-parsing is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Sub-skill of json-config-loader: 1. Key=Value Configuration Parsing (+1).

Teams using json-config-loader-1-keyvalue-configuration-parsing should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/1-keyvalue-configuration-parsing/SKILL.md --create-dirs "https://raw.githubusercontent.com/vamseeachanta/workspace-hub/main/.agents/skills/_core/bash/json-config-loader/1-keyvalue-configuration-parsing/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/1-keyvalue-configuration-parsing/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How json-config-loader-1-keyvalue-configuration-parsing Compares

Feature / Agentjson-config-loader-1-keyvalue-configuration-parsingStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Sub-skill of json-config-loader: 1. Key=Value Configuration Parsing (+1).

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# 1. Key=Value Configuration Parsing (+1)

## 1. Key=Value Configuration Parsing


Parse simple key=value configuration files:

```bash
#!/bin/bash
# ABOUTME: Parse key=value configuration files
# ABOUTME: Supports comments, empty lines, and quoted values

CONFIG_FILE="${1:-config.conf}"

# Declare associative array for config
declare -A CONFIG

# Parse configuration file
parse_config() {
    local file="$1"

    if [[ ! -f "$file" ]]; then
        echo "Error: Config file not found: $file" >&2
        return 1
    fi

    while IFS= read -r line || [[ -n "$line" ]]; do
        # Skip comments and empty lines
        [[ "$line" =~ ^[[:space:]]*# ]] && continue
        [[ -z "${line// /}" ]] && continue

        # Parse key=value pairs
        if [[ "$line" =~ ^([^=]+)=(.*)$ ]]; then
            local key="${BASH_REMATCH[1]}"
            local value="${BASH_REMATCH[2]}"

            # Trim whitespace
            key="${key#"${key%%[![:space:]]*}"}"
            key="${key%"${key##*[![:space:]]}"}"
            value="${value#"${value%%[![:space:]]*}"}"
            value="${value%"${value##*[![:space:]]}"}"

            # Remove surrounding quotes if present
            if [[ "$value" =~ ^\"(.*)\"$ ]] || [[ "$value" =~ ^\'(.*)\'$ ]]; then
                value="${BASH_REMATCH[1]}"
            fi

            CONFIG["$key"]="$value"
        fi
    done < "$file"
}

# Get config value with default
get_config() {
    local key="$1"
    local default="${2:-}"

    echo "${CONFIG[$key]:-$default}"
}

# Check if key exists
has_config() {
    local key="$1"
    [[ -v CONFIG[$key] ]]
}

# Usage
parse_config "$CONFIG_FILE"

# Access values
echo "Database: $(get_config 'database' 'default.db')"
echo "Port: $(get_config 'port' '8080')"

if has_config 'debug'; then
    echo "Debug mode enabled"
fi
```


## 2. JSON Configuration with jq


Load and manipulate JSON configuration:

```bash
#!/bin/bash
# ABOUTME: JSON configuration loading with jq
# ABOUTME: Provides safe defaults and nested value access

# Check jq dependency
check_jq() {
    if ! command -v jq &> /dev/null; then
        echo "Error: jq is required but not installed" >&2
        echo "Install with: apt install jq (Ubuntu) or brew install jq (Mac)" >&2
        exit 1
    fi
}

# Load JSON config file
load_json_config() {
    local file="$1"

    if [[ ! -f "$file" ]]; then
        echo "{}"
        return 1
    fi

    # Validate JSON
    if ! jq empty "$file" 2>/dev/null; then
        echo "Error: Invalid JSON in $file" >&2
        echo "{}"
        return 1
    fi

    cat "$file"
}

# Get value from JSON with default
json_get() {
    local json="$1"
    local path="$2"
    local default="${3:-}"

    local value
    value=$(echo "$json" | jq -r "$path // empty" 2>/dev/null)

    if [[ -z "$value" || "$value" == "null" ]]; then
        echo "$default"
    else
        echo "$value"
    fi
}

# Get array from JSON
json_get_array() {
    local json="$1"
    local path="$2"

    echo "$json" | jq -r "$path[]? // empty" 2>/dev/null
}

# Check if path exists in JSON
json_has() {
    local json="$1"
    local path="$2"

    local result
    result=$(echo "$json" | jq -e "$path != null" 2>/dev/null)
    [[ "$result" == "true" ]]
}

# Usage example
check_jq

CONFIG_JSON=$(load_json_config "config.json")

# Access nested values
DB_HOST=$(json_get "$CONFIG_JSON" '.database.host' 'localhost')
DB_PORT=$(json_get "$CONFIG_JSON" '.database.port' '5432')
DEBUG=$(json_get "$CONFIG_JSON" '.settings.debug' 'false')

echo "Database: $DB_HOST:$DB_PORT"
echo "Debug: $DEBUG"

# Iterate array values
echo "Enabled features:"
while IFS= read -r feature; do
    echo "  - $feature"
done < <(json_get_array "$CONFIG_JSON" '.features')
```

Related Skills

toml-section-scoping-config-debug

5
from vamseeachanta/workspace-hub

Diagnose TOML config errors caused by misplaced keys in table sections

portable-config-baseline-pattern

5
from vamseeachanta/workspace-hub

Extract machine-agnostic settings into portable template files while keeping machine-specific hooks and plugins separate

portable-baseline-configuration-pattern

5
from vamseeachanta/workspace-hub

Separate portable/universal config from machine-specific settings to enable safe template reuse across environments

portable-baseline-config-pattern

5
from vamseeachanta/workspace-hub

Separate machine-portable baseline config from environment-specific hooks and plugins

codex-skill-loader-broken-symlink-recovery

5
from vamseeachanta/workspace-hub

Diagnose Codex startup failures in workspace-hub caused by a broken `.Codex/skills/skills` symlink and recover without misattributing the failure to issue scope.

orcaflex-environment-config

5
from vamseeachanta/workspace-hub

Configure OrcaFlex environmental conditions including wave spectra (JONSWAP, Dean Stream), current profiles, wind loading, and seabed properties for offshore analysis.

hermes-config-audit-gotchas

5
from vamseeachanta/workspace-hub

Audit Hermes custom config keys and migrated skill settings safely, with verified command behavior and stale-path checks.

hermes-local-configuration

5
from vamseeachanta/workspace-hub

Class-level Hermes local configuration and setup workflows, including config audit gotchas and Windows installation.

mkdocs-8-plugin-configuration

5
from vamseeachanta/workspace-hub

Sub-skill of mkdocs: 8. Plugin Configuration (+4).

json-config-loader-6-yaml-configuration-via-yq

5
from vamseeachanta/workspace-hub

Sub-skill of json-config-loader: 6. YAML Configuration (via yq).

json-config-loader-5-environment-variable-configuration

5
from vamseeachanta/workspace-hub

Sub-skill of json-config-loader: 5. Environment Variable Configuration.

json-config-loader-4-multi-section-ini-parsing

5
from vamseeachanta/workspace-hub

Sub-skill of json-config-loader: 4. Multi-Section INI Parsing.