Skip to main content Skills Marketplace Descubra e explore skills de IA criadas pela comunidade.
Instalar com Codex ou Claude Copie este prompt, cole no Codex, Claude ou outro assistente e deixe que ele revise a página da skill e instale para você.
Copiar promptMostrar detalhes do prompt Um comando direto ignora o prompt de revisão. Verifique a origem antes de executá-lo.
npx skills add https://github.com/vamseeachanta/workspace-hub --skill json-config-loaderO comando permanece em uma só linha. Role horizontalmente para revisá-lo antes de copiar.
Prefere uma cópia local? Baixe os arquivos disponíveis atualmente no SkillsMP.
Baixar Zip Baixando... Mais deste repositório Write outbound email and external messages in Vamsee Achanta's voice — a subtle offer to help, never bold or rash claims. Load before drafting ANY email, LinkedIn/Collide reply, proposal note, or outreach sent under his name.
Save/publish analysis or computation results from ANY ecosystem repo to Hugging Face as a queryable, viewer-renderable dataset. Use when the user wants to "save results to hugging face", "publish dataset to HF", "hugging face data saving", "save analysis results", "hf dataset", "make results queryable", or "render via datasets-server API". Reshapes nested results into flat parquet tables, writes a dataset card with a viewer `configs:` block and provenance, applies license/public-vs-private routing, enforces a domain data-quality gate (faithful-to-source != correct), publishes to `aceengineer/<repo>-<projection>`, and verifies via the datasets-server API.
Clone, create, fork, configure, and manage GitHub repositories. Manage remotes, secrets, releases, and workflows. Works with gh CLI or falls back to git + GitHub REST API via curl.
Ocupações relacionadas SOC
Baseado na classificação ocupacional SOC
name json-config-loader version 1.0.0 description Configuration file parsing patterns for bash scripts (INI, key=value, JSON) author workspace-hub category bash tags ["bash","config","json","yaml","parsing","jq","configuration"] platforms ["linux","macos"]
JSON & Config Loader
Patterns for loading, parsing, and generating configuration files in bash scripts. Supports key=value files, JSON with jq, and associative array management. Extracted from workspace-hub's configuration scripts.
When to Use This Skill
✅ Use when:
Loading configuration from files into bash scripts
Parsing key=value or INI-style configuration files
Working with JSON data using jq
Generating JSON reports from bash
Managing configuration with associative arrays
❌ Avoid when:
Complex nested configuration (consider Python instead)
Real-time configuration changes (use a daemon)
Configuration with complex validation rules
Core Capabilities
1. Key=Value Configuration Parsing
Parse simple key=value configuration files:
#!/bin/bash
CONFIG_FILE="${1:-config.conf} "
declare -A CONFIG
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
[[ "$line " =~ ^[[:space:]]*# ]] && continue
[[ -z "${line// /} " ]] && continue
if [[ "$line " =~ ^([^=]+)=(.*)$ ]]; then
local key="${BASH_REMATCH[1]} "
local value="${BASH_REMATCH[2]} "
key="${key#"${key%%[![:space:]]*} "} "
key=
value=
value=
[[ =~ ^\"(.*)\"$ ]] || [[ =~ ^\'(.*)\'$ ]];
value=
CONFIG[ ]=
<
}
() {
key=
default=
}
() {
key=
[[ -v CONFIG[ ] ]]
}
parse_config
has_config ;
2. JSON Configuration with jq
Load and manipulate JSON configuration:
#!/bin/bash
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 () {
local file="$1 "
if [[ ! -f "$file " ]]; then
echo "{}"
return 1
fi
if ! jq empty "$file " 2>/dev/null; then
echo "Error: Invalid JSON in $file " >&2
echo "{}"
return 1
fi
cat "$file "
}
json_get () {
local json="$1 "
local path=
default=
value
value=$( | jq -r 2>/dev/null)
[[ -z || == ]];
}
() {
json=
path=
| jq -r 2>/dev/null
}
() {
json=
path=
result
result=$( | jq -e 2>/dev/null)
[[ == ]]
}
check_jq
CONFIG_JSON=$(load_json_config )
DB_HOST=$(json_get )
DB_PORT=$(json_get )
DEBUG=$(json_get )
IFS= -r feature;
< <(json_get_array )
3. JSON Report Generation
Generate structured JSON reports:
#!/bin/bash
generate_json_object () {
local -n data=$1
local json="{}"
for key in "${!data[@]} " ; do
local value="${data[$key]} "
json=$(echo "$json " | jq --arg k "$key " --arg v "$value " '. + {($k): $v}' )
done
echo "$json "
}
generate_report () {
local status="$1 "
local total="$2 "
local errors="$3 "
local warnings="$4 "
jq -n \
--arg status "$status " \
--arg timestamp "$(date -Iseconds) " \
--arg run_id "$(date +%Y%m%d-%H%M%S) " \
--argjson total \
--argjson errors \
--argjson warnings \
}
() {
report=
items=( )
items_json=
item ;
items_json=$( | jq --arg i )
| jq --argjson items
}
() {
report=
file=
-p
| jq >
}
report=$(generate_report 100 5 10)
report=$(add_report_items )
save_report
4. Multi-Section INI Parsing
Parse INI-style files with sections:
#!/bin/bash
declare -A INI_CONFIG
declare -a INI_SECTIONS=()
parse_ini () {
local file="$1 "
local current_section="default"
if [[ ! -f "$file " ]]; then
echo "Error: INI file not found: $file " >&2
return 1
fi
INI_SECTIONS=("default" )
while IFS= read -r line || [[ -n "$line " ]]; do
[[ "$line " =~ ^[[:space:]]*[#\;] ]] && continue
[[ -z "${line// /} " ]] && continue
if [[ "$line " =~ ^\[([^\]]+)\] ]]; then
current_section="${BASH_REMATCH[1]} "
INI_SECTIONS+=("$current_section " )
continue
fi
if [[ "$line " =~ ^([^=]+)=(.*)$ ]];
key=
value=
key=
key=
value=
value=
INI_CONFIG[ ]=
<
}
() {
section=
key=
default=
}
() {
section=
prefix=
key ;
[[ == * ]];
}
() {
| -u
}
parse_ini
DB_HOST=$(ini_get )
DB_PORT=$(ini_get )
LOG_LEVEL=$(ini_get )
key $(ini_section_keys );
5. Environment Variable Configuration
Load configuration with environment variable overrides:
#!/bin/bash
declare -A APP_CONFIG
load_config_with_env () {
local file="$1 "
local prefix="${2:-APP_} "
if [[ -f "$file " ]]; then
while IFS= read -r line || [[ -n "$line " ]]; do
[[ "$line " =~ ^[[:space:]]*# ]] && continue
[[ -z "${line// /} " ]] && continue
if [[ "$line " =~ ^([^=]+)=(.*)$ ]]; then
local key="${BASH_REMATCH[1]} "
local value="${BASH_REMATCH[2]} "
key="${key#"${key%%[![:space:]]*} "} "
key="${key%"${key##*[![:space:]]} "} "
APP_CONFIG["$key " ]="$value "
<
key ;
env_key=
env_key=
[[ -v ]];
APP_CONFIG[ ]=
}
() {
missing=()
key ;
[[ -z ]];
missing+=( )
[[ -gt 0 ]];
>&2
>&2
1
0
}
() {
key=
default=
}
() {
key=
default=
value=
[[ =~ ^-?[0-9]+$ ]];
}
() {
key=
default=
value=
| |1|on) ;;
|no|0|off) ;;
*) ;;
}
load_config_with_env
require_config || 1
PORT=$(config_int 8080)
DEBUG=$(config_bool )
API_KEY=$(config_string )
6. YAML Configuration (via yq)
Parse YAML files when yq is available:
#!/bin/bash
get_yaml_parser () {
if command -v yq &> /dev/null; then
echo "yq"
elif command -v jq &> /dev/null; then
echo "jq"
else
echo "none"
fi
}
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)
jq '.' "$file " 2>/dev/null || echo "{}"
;;
*)
>&2
1
;;
}
() {
file=
path=
default=
parser
parser=$(get_yaml_parser)
value
yq)
value=$(yq -r 2>/dev/null)
;;
jq)
value=$(jq -r 2>/dev/null)
;;
*)
value=
;;
[[ -z || == ]];
}
CONFIG_FILE=
CONFIG_JSON=$(load_yaml_config )
DB_HOST=$(yaml_get )
DB_PORT=$(yaml_get )
Complete Example: Config Manager
Full configuration management with multiple formats:
#!/bin/bash
set -e
declare -A CONFIG
CONFIG_FILE=""
CONFIG_FORMAT=""
detect_format () {
local file="$1 "
case "${file##*.} " in
json) echo "json" ;;
yaml|yml) echo "yaml" ;;
ini) echo "ini" ;;
*) echo "keyvalue" ;;
esac
}
load_keyvalue () {
local file="$1 "
while IFS= read -r line || [[ -n "$line " ]]; do
[[ "$line " =~ ^[[:space:]]*# ]] &&
[[ -z ]] &&
[[ =~ ^([^=]+)=(.*)$ ]];
key=
value=
value=
CONFIG[ ]=
<
}
() {
file=
! -v jq &> /dev/null;
>&2
1
IFS= -r key value;
CONFIG[ ]=
< <(jq -r 2>/dev/null)
}
() {
file=
env_prefix=
[[ ! -f ]];
>&2
1
CONFIG=()
CONFIG_FILE=
CONFIG_FORMAT=$(detect_format )
json) load_json ;;
*) load_keyvalue ;;
[[ -n ]];
key ;
env_key=
env_key=
env_key=
[[ -v ]];
CONFIG[ ]=
}
() {
key=
default=
}
() {
key=
value=
CONFIG[ ]=
}
() {
[[ -v CONFIG[ ] ]]
}
() {
|
}
() {
key $(config_keys);
}
() {
json=
key ;
json=$( | jq --arg k --arg v )
| jq
}
() {
missing=()
key ;
! config_has || [[ -z ]];
missing+=( )
[[ -gt 0 ]];
>&2
>&2
1
}
() {
key=
value
value=$(config_get )
[[ -n && ! =~ ^-?[0-9]+$ ]];
>&2
1
}
() {
key=
value
value=$(config_get )
[[ -n && ! =~ ^https?:// ]];
>&2
1
}
[[ == ]];
config_load
config_require || 1
config_validate_int || 1
config_validate_url || 1
config_dump
Best Practices
1. Always Provide Defaults
value=$(config_get "key" "default_value" )
2. Validate Early
config_require "api_key" "database_url" || exit 1
3. Use Environment Overrides for Secrets
API_KEY="${API_KEY:-$(config_get 'api_key')} "
4. Validate JSON with jq
if ! jq empty "$file " 2>/dev/null; then
echo "Invalid JSON" >&2
exit 1
fi
5. Handle Missing Files Gracefully
if [[ -f "$config_file " ]]; then
load_config "$config_file "
else
echo "Warning: Config not found, using defaults" >&2
fi
Resources
Version History
1.0.0 (2026-01-14): Initial release - extracted from workspace-hub configuration scripts
"${key%"${key##*[![:space:]]} "} "
"${value#"${value%%[![:space:]]*} "} "
"${value%"${value##*[![:space:]]} "} "
if
"$value "
"$value "
then
"${BASH_REMATCH[1]} "
fi
"$key "
"$value "
fi
done
"$file "
get_config
local
"$1 "
local
"${2:-} "
echo
"${CONFIG[$key]:-$default } "
has_config
local
"$1 "
$key
"$CONFIG_FILE "
echo
"Database: $(get_config 'database' 'default.db') "
echo
"Port: $(get_config 'port' '8080') "
if
'debug'
then
echo
"Debug mode enabled"
fi
"$2 "
local
"${3:-} "
local
echo
"$json "
"$path // empty"
if
"$value "
"$value "
"null"
then
echo
"$default "
else
echo
"$value "
fi
json_get_array
local
"$1 "
local
"$2 "
echo
"$json "
"$path []? // empty"
json_has
local
"$1 "
local
"$2 "
local
echo
"$json "
"$path != null"
"$result "
"true"
"config.json"
"$CONFIG_JSON "
'.database.host'
'localhost'
"$CONFIG_JSON "
'.database.port'
'5432'
"$CONFIG_JSON "
'.settings.debug'
'false'
echo
"Database: $DB_HOST :$DB_PORT "
echo
"Debug: $DEBUG "
echo
"Enabled features:"
while
read
do
echo
" - $feature "
done
"$CONFIG_JSON "
'.features'
"$total "
"$errors "
"$warnings "
'{
metadata: {
status: $status,
timestamp: $timestamp,
run_id: $run_id
},
summary: {
total_processed: $total,
errors: $errors,
warnings: $warnings,
success_rate: (if $total > 0 then (($total - $errors) * 100 / $total) else 0 end)
}
}'
add_report_items
local
"$1 "
shift
local
"$@ "
local
"[]"
for
in
"${items[@]} "
do
echo
"$items_json "
"$item "
'. + [$i]'
done
echo
"$report "
"$items_json "
'. + {items: $items}'
save_report
local
"$1 "
local
"$2 "
mkdir
"$(dirname "$file " ) "
echo
"$report "
'.'
"$file "
echo
"Report saved: $file "
"success"
"$report "
"item1"
"item2"
"item3"
"$report "
"reports/analysis-$(date +%Y%m%d) .json"
then
local
"${BASH_REMATCH[1]} "
local
"${BASH_REMATCH[2]} "
"${key#"${key%%[![:space:]]*} "} "
"${key%"${key##*[![:space:]]} "} "
"${value#"${value%%[![:space:]]*} "} "
"${value%"${value##*[![:space:]]} "} "
"${current_section} .${key} "
"$value "
fi
done
"$file "
ini_get
local
"$1 "
local
"$2 "
local
"${3:-} "
echo
"${INI_CONFIG["${section} .${key} "]:-$default } "
ini_section_keys
local
"$1 "
local
"${section} ."
for
in
"${!INI_CONFIG[@]} "
do
if
"$key "
"${prefix} "
then
echo
"${key#$prefix} "
fi
done
ini_sections
printf
'%s\n'
"${INI_SECTIONS[@]} "
sort
"settings.ini"
"database"
"host"
"localhost"
"database"
"port"
"5432"
"logging"
"level"
"INFO"
echo
"Database: $DB_HOST :$DB_PORT "
echo
"Log Level: $LOG_LEVEL "
echo
"Database settings:"
for
in
"database"
do
echo
" $key = $(ini_get "database" "$key " ) "
done
fi
done
"$file "
fi
for
in
"${!APP_CONFIG[@]} "
do
local
"${prefix} ${key^^} "
"${env_key//-/_} "
if
"$env_key "
then
"$key "
"${!env_key} "
fi
done
require_config
local
for
in
"$@ "
do
if
"${APP_CONFIG[$key]:-} "
then
"$key "
fi
done
if
${#missing[@]}
then
echo
"Error: Missing required configuration:"
printf
" - %s\n"
"${missing[@]} "
return
fi
return
config_string
local
"$1 "
local
"${2:-} "
echo
"${APP_CONFIG[$key]:-$default } "
config_int
local
"$1 "
local
"${2:-0} "
local
"${APP_CONFIG[$key]:-$default } "
if
"$value "
then
echo
"$value "
else
echo
"$default "
fi
config_bool
local
"$1 "
local
"${2:-false} "
local
"${APP_CONFIG[$key]:-$default } "
case
"${value,,} "
in
true
yes
echo
"true"
false
echo
"false"
echo
"$default "
esac
"app.conf"
"MYAPP_"
"api_key"
"database_url"
exit
"port"
"debug"
false
"api_key"
echo
"Starting on port $PORT (debug: $DEBUG )"
echo
"Error: No YAML parser available (install yq or jq)"
echo
"{}"
return
esac
yaml_get
local
"$1 "
local
"$2 "
local
"${3:-} "
local
local
case
"$parser "
in
"$path // \"$default \""
"$file "
"$path // \"$default \""
"$file "
"$default "
esac
if
"$value "
"$value "
"null"
then
echo
"$default "
else
echo
"$value "
fi
"config.yaml"
"$CONFIG_FILE "
"$CONFIG_FILE "
'.database.host'
'localhost'
"$CONFIG_FILE "
'.database.port'
'5432'
echo
"Database: $DB_HOST :$DB_PORT "
continue
"${line// /} "
continue
if
"$line "
then
local
"${BASH_REMATCH[1]// /} "
local
"${BASH_REMATCH[2]} "
"${value#"${value%%[![:space:]]*} "} "
"$key "
"$value "
fi
done
"$file "
load_json
local
"$1 "
if
command
then
echo
"Error: jq required for JSON config"
return
fi
while
"="
read
do
"$key "
"$value "
done
'paths(scalars) as $p | "\($p | join("."))"+"="+"\(getpath($p))"'
"$file "
config_load
local
"$1 "
local
"${2:-} "
if
"$file "
then
echo
"Error: Config file not found: $file "
return
fi
"$file "
"$file "
case
"$CONFIG_FORMAT "
in
"$file "
"$file "
esac
if
"$env_prefix "
then
for
in
"${!CONFIG[@]} "
do
local
"${env_prefix} ${key^^} "
"${env_key//./_} "
"${env_key//-/_} "
if
"$env_key "
then
"$key "
"${!env_key} "
fi
done
fi
echo
"Loaded ${#CONFIG[@]} config values from $file ($CONFIG_FORMAT )"
config_get
local
"$1 "
local
"${2:-} "
echo
"${CONFIG[$key]:-$default } "
config_set
local
"$1 "
local
"$2 "
"$key "
"$value "
config_has
$1
config_keys
printf
'%s\n'
"${!CONFIG[@]} "
sort
config_dump
echo
"# Configuration ($CONFIG_FORMAT from $CONFIG_FILE )"
for
in
do
echo
"$key =${CONFIG[$key]} "
done
config_to_json
local
"{}"
for
in
"${!CONFIG[@]} "
do
echo
"$json "
"$key "
"${CONFIG[$key]} "
'. + {($k): $v}'
done
echo
"$json "
'.'
config_require
local
for
in
"$@ "
do
if
"$key "
"$(config_get "$key " ) "
then
"$key "
fi
done
if
${#missing[@]}
then
echo
"Error: Missing required config keys:"
printf
" - %s\n"
"${missing[@]} "
return
fi
config_validate_int
local
"$1 "
local
"$key "
if
"$value "
"$value "
then
echo
"Error: $key must be an integer (got: $value )"
return
fi
config_validate_url
local
"$1 "
local
"$key "
if
"$value "
"$value "
then
echo
"Error: $key must be a URL (got: $value )"
return
fi
if
"${BASH_SOURCE[0]} "
"${0} "
then
"${1:-config.conf} "
"APP_"
"database_host"
"api_key"
exit
"port"
exit
"api_endpoint"
exit
echo
"Host: $(config_get 'database_host' 'localhost') "
echo
"Port: $(config_get 'port' '5432') "
echo
""
fi