#16753·foundry

feat(cast): add structured JSON output for cast source

Author: OsrakaCreated Sep 9, 2026Updated Sep 9, 2026

Component

Cast

Describe the feature you would like

cast source <address> --json currently emits the same raw, multi-line Solidity source as text mode instead of a JSON document. This is reproducible without an external explorer by extending the existing source_plain_and_directory Axum fixture in crates/cast/tests/cli/source.rs: invoke the same mocked cast source command with --json, and parsing stdout with serde_json fails.

Observed stdout:

pragma solidity ^0.8.0;
contract Example {}

docs/dev/output-channels.md defines the target contract for --json as a single JSON document, and crates/cast/src/args.rs already leaves a TODO(json) on the Source branch for this case. I also checked open and closed issues/PRs for this exact command/output combination and did not find an existing item.

Before implementing it, I would like to confirm the intended payload and directory semantics:

  1. For stdout mode, should data be the source string directly, or an object such as { "source": "..." }?
  2. Should flattened and non-flattened stdout use the same shape?
  3. With --directory, should JSON mode keep stdout empty because the primary result is written to disk, or emit a path/file manifest?

A minimal first PR can preserve all text-mode behavior, add mocked CLI regressions, and only route the agreed --json paths through the existing JsonEnvelope helpers. No explorer or network dependency would be needed in the tests.