Skip to content

feat(builtins): implement jq --arg and --argjson flags #914

@chaliy

Description

@chaliy

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions