{
  "id": 23747671,
  "title": "jq --arg vs --argjson: keep build ID 001 from turning into 1",
  "url": "https://urgent.news/2026/12/06/jq-arg-vs-argjson-keep-build-id-001-from-turning-into-1",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-12-06T01:58:19.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/lena-money/jq-arg-vs-argjson-keep-build-id-001-from-turning-into-1-418n"
  },
  "original_language": null,
  "account": "The release job is given two strings: the build ID \"001\" and the dry-run setting \"false\". The manifest requires keeping the first as text and turning the second into a boolean. The --arg flag is used for the build ID and --argjson for the dry-run flag. Starting with jq 1.7, the command jq -n --argjson id 001 '$id' printed \"1\" instead of \"001\", as JSON numbers cannot have leading zeros. This discrepancy can lead to errors if the wrong type is used for a field with different implications. For instance, treating the ID as a small integer changes the name of the artifact, while treating the dry-run flag as a boolean decides whether to write a report or deploy. The minimal example using jq -n --arg id \"$build_id\" --argjson dry \"$dry_run\" '{build_id: $id, dry_run: $dry}' shows that the ID is printed as a string while the dry-run flag is printed as the JSON literal \"false\".\n\nWhen a shell variable containing \"false\" is passed as --arg, it becomes a JSON string and selects the wrong branch. This issue is not caused by Bash's test behavior but by jq's handling of JSON inputs. To avoid confusion, the type of each field should be decided before choosing the flags. If the output fields are known, the flags can be chosen accordingly. For instance, the build ID is a label and must be kept as text, while the dry-run flag is a decision and must be a boolean. In the manifest, the build ID is a policy field from \"0\" to \"10\", and a test must be run with \"false\" to ensure the correct branch is selected. The contract for the input should be checked separately for each field, and values that could be misinterpreted should be rejected. The final JSON file should be checked to ensure it meets the expected format and type for each field.",
  "summary": "The shell hands a release job two strings: the build ID 001 and the dry-run setting false . The manifest needs to keep the first as text and turn the second into a boolean. Use --arg for the ID and --argjson for the trusted boolean literal. With jq 1.7, jq -n --argjson id 001 '$id' printed 1 on my machine. JSON numbers do not allow leading zeros, so don't rely on another parser accepting that…",
  "summary_source": "publisher",
  "key_points": [
    "\"001\" build ID kept as text using --arg flag",
    "\"false\" dry-run flag converted to JSON boolean",
    "jq 1.7 change causes ID to print as number 1"
  ],
  "editors_take": "Choosing the wrong flag can change artifact names or deployment decisions, so developers must match input types to the expected manifest format to avoid errors.",
  "opinion": false,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "outlets_capped": false,
    "also_reported_by": []
  },
  "machine_translated": false,
  "ai_generated": true,
  "disclaimer": "Accounts, briefs, key points, the editor’s take and translations are written by software from other outlets’ reporting and may contain errors. A summary whose summary_source is \"publisher\" is the outlet’s own feed text. Always check the linked original."
}