Parse Dosya CLI JSON in a script

Preserve the Dosya CLI exit status, parse valid command-specific JSON even for partial failures, and gate dependent work on a verified success.

Last reviewed

A robust shell wrapper preserves the Dosya process status before running jq. JSON output is command-specific, and batch commands normally emit usable success and failure receipts before exiting 1 when any member failed.

Four workflow panels show separating output, preserving the CLI exit class, validating command-specific JSON, and inspecting batch failure receipts.
The diagram covers separating output, preserving the CLI exit class, validating command-specific JSON, and inspecting batch failure receipts before dependent work. Open full-size screenshot.

Before you start

  • Use temporary files with restrictive permissions for outputs that may contain names or IDs.
  • Keep set -o pipefail when using a pipeline, or avoid a pipeline so the parser cannot hide the CLI status.
  • Choose a precise jq -e assertion for the command’s documented response.

Steps

  1. Create separate stdout and stderr files, then run the command with --json; for example, dosya whoami --json >result.json 2>result.err.
  2. Capture status=$? immediately and classify it without replacing it with jq’s status. Keep stderr beside that original numeric result.
  3. When stdout is nonempty, run jq -e . result.json even after a nonzero exit. Preserve valid command output; if parsing fails, report that separately without losing the Dosya status.
  4. Apply a command-specific selector, such as the required user identifier from whoami or the expected item collection from ls. There is no universal response envelope.
  5. For mv, rm, recursive download, trash, star, or sync batches, inspect the command’s failures entries and successful counts. Partial work normally produces valid JSON and exits 1.
  6. Start dependent work only when the Dosya status is 0 and the command-specific postcondition passes. Retain a sanitized partial receipt for recovery, then remove sensitive temporary files.
Dosya CLI overview with installation and command references for parse dosya cli json in a script.
The CLI overview supplies the installation and command references used by “Parse Dosya CLI JSON in a script”. Open full-size screenshot.

Expected result

The wrapper preserves the CLI failure class, extracts useful receipts from valid nonzero output, and starts dependent work only after exit 0 and the command-specific postcondition both pass.

Troubleshooting

The JSON file is empty. Read stderr and the saved process status; do not let jq become the reported failure.

A batch exits 1 with valid JSON. Preserve successful counts and failure entries, repair or report each failed member, and keep the overall task unsuccessful.

Warnings break parsing. They should be on stderr. Remove stream merging and confirm the wrapper invokes the current CLI binary.

Was this helpful?

Loading helpfulness results…

Voting saves a necessary ballot cookie for up to 180 days so you can change your answer.

Questions and replies

Ask about the steps in this guide. Questions are reviewed before publication.

Keep account details, credentials and private files out of public questions. Use private support for those.

Loading questions…

    Sign in to your Dosya account to ask a question.

    Check the outcome before you retry

    Use these shared checks when a task needs a second look.