Verify jq and yq commands work correctly.
# Check tools are installed
jq --version # jq-1.7+
yq --version # yq 4.x (Mike Farah's version)
echo '{"name": "test-app", "version": "1.0.0"}' | jq '.name'
Expected: "test-app"
echo '{"scripts": {"build": "tsc", "test": "jest"}}' | jq '.scripts.build'
Expected: "tsc"
echo '{"users": [{"name": "Alice", "active": true}, {"name": "Bob", "active": false}]}' | jq '.users[] | select(.active == true) | .name'
Expected: "Alice"
echo '{"items": [1, 2, 3, 4, 5]}' | jq '.items | length'
Expected: 5
echo '{"name": "myapp"}' | jq -r '.name'
Expected: myapp (no quotes)
echo '{"users": [{"id": 1, "name": "Alice"}, {"id": 2, "name": "Bob"}]}' | jq '.users | map({id, name})'
Expected: Array with id and name objects
echo 'name: myapp
version: 2.0.0' | yq '.name'
Expected: myapp
echo 'database:
host: localhost
port: 5432' | yq '.database | keys'
Expected: - host and - port
echo 'services:
web:
image: nginx
db:
image: postgres' | yq '.services | keys'
Expected: - web and - db
echo '[package]
name = "myapp"
version = "1.0.0"' | yq -p toml '.package.name'
Expected: myapp
Create a test file and verify full workflow:
cat > /tmp/test-package.json << 'EOF'
{
"name": "test-project",
"version": "1.0.0",
"dependencies": {
"express": "^4.18.0",
"lodash": "^4.17.21"
},
"scripts": {
"start": "node index.js",
"test": "jest"
}
}
EOF
# Extract dependencies
jq '.dependencies | keys' /tmp/test-package.json
# Extract scripts
jq '.scripts' /tmp/test-package.json
# Get version as raw string
jq -r '.version' /tmp/test-package.json
# Cleanup
rm /tmp/test-package.json
Expected:
["express", "lodash"]1.0.0