Construct Json (with ENV variables in BASH)

TLDR simplest string friendly example

  jq --null-input --compact-output 'env | {
    name: .ENV_VARIABLE_IN_YOUR_ENVIRONMENT,
    tags: ["developer", "linux"]
  }'

Construct JSON from environment variables

  # 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"]
  }'
# Output
{"name":"John Doe","age":30,"active":true,"tags":["developer","linux"]}

To use local or un-exported values use args

# NOTE: usage of arg for string and argjson for number
main() {
 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