Problem
jq --arg name value and jq --argjson name value are commonly used flags for safely injecting variables into jq filters without shell interpolation. They are the recommended way to pass dynamic values into jq expressions.
Expected behavior
jq --arg name "John" '.greeting = "Hello " + $name' <<< '{}'
# {"greeting": "Hello John"}
jq --argjson count 42 '.total = $count' <<< '{}'
# {"total": 42}
# Multiple args
jq --arg key "name" --arg val "Alice" '.[$key] = $val' <<< '{}'
# {"name": "Alice"}
--arg binds a string value, --argjson binds a parsed JSON value.
References
Problem
jq --arg name valueandjq --argjson name valueare commonly used flags for safely injecting variables into jq filters without shell interpolation. They are the recommended way to pass dynamic values into jq expressions.Expected behavior
--argbinds a string value,--argjsonbinds a parsed JSON value.References