# Note the values MUST be exported for 'env' function to access them export NAME="John Doe" export AGE=30 export ACTIVE=true # test("true"; "i") - used for case insensitive match of "true" string jq --null-input --compact-output 'env | { name: .NAME, age: (.AGE | tonumber), active: (.ACTIVE | test("true"; "i")), tags: ["developer", "linux"] }'
# NOTE: usage of arg for string and argjson for numbermain() { local name="John Doe" local age=30 jq -nc \ --arg name "$name" \ --argjson age "$age" \ '{name: $name, age: $age}'}main
# Output{"name":"John Doe","age":30}
Side note
You can construct inline JSON manually
main() { local debug_mode=true # Boolean - no quotes local port=8080 # Number - no quotes local active=false # Boolean - no quotes local name="John Doe" # String - needs quotes local value=null # Null - no quotes CONFIG="{ \"debug\": $debug_mode, \"port\": $port, \"active\": $active, \"name\": \"$name\", \"value\": $value }" echo "$CONFIG"}main