foundry-rs / foundry-rs/foundry

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

Open
#16,753 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
10.6k
Forks
2.6k
Avg merge
18h 20m
Merged PRs (30d)
510

Description

### Component

Cast

### Describe the feature you would like

`cast source

--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:

```text
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.

Contributor guide

Open the contributing guide

Research direction

Read docs/dev/output-channels.md and the TODO(json) on the Source branch in crates/cast/src/args.rs, then run the source_plain_and_directory fixture in crates/cast/tests/cli/source.rs. Confirm the intended stdout and --directory semantics with the maintainer, add regression coverage for the agreed JSON contract, and ensure the mocked command output parses as JSON without changing text-mode behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust, solidity
Domain
cli, tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.