Skip to content

feat(search): --json JSON Lines output (ripgrep-compatible)#6

Merged
botirk38 merged 2 commits intomasterfrom
feat/json-output
Apr 3, 2026
Merged

feat(search): --json JSON Lines output (ripgrep-compatible)#6
botirk38 merged 2 commits intomasterfrom
feat/json-output

Conversation

@botirk38
Copy link
Copy Markdown
Owner

@botirk38 botirk38 commented Apr 3, 2026

Summary

Adds --json / --no-json (last flag wins) and SearchOutputFormat::Json in sift-core. Search uses grep_printer::JSON with sink_with_path so stdout matches ripgrep's JSON Lines format: begin, match, context, end per file, plus a final summary object with elapsed_total and aggregated stats.

Behavior (aligned with rg)

  • Incompatible with --count, --count-matches, --files-with-matches, --files-without-match (clear error).
  • --json implies line numbers for the search and stderr stats (like rg's implicit --stats).
  • Quiet + JSON: no per-file match JSON to stdout; summary line still emitted.

API

  • SearchOutput.format: SearchOutputFormat (Text | Json).
  • Errors: JsonOutputIncompatibleMode, JsonSerialize.

Tests / docs

  • crates/cli/tests/integration_json.rs
  • docs/rg-compat-matrix.md (--json row)

Validation

cargo fmt --check, cargo clippy -D warnings, cargo test --workspace --all-features

Add SearchOutputFormat Text|Json and wire grep_printer::JSON for standard/
only-matching search. Emit begin/match/context/end per file plus final
summary; quiet JSON discards match lines but keeps summary. CLI: --json/
--no-json, conflicts with count/file-list modes, implicit stderr stats.
Integration tests and rg compat matrix updated.
@botirk38 botirk38 merged commit 5eedaf2 into master Apr 3, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant