Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: --json output (ideally the same as rg) #78

Open
simonw opened this issue Dec 2, 2020 · 2 comments
Open

Feature request: --json output (ideally the same as rg) #78

simonw opened this issue Dec 2, 2020 · 2 comments

Comments

@simonw
Copy link

simonw commented Dec 2, 2020

I built a web interface for rg which works by shelling out to a rg --json process. Here's a demo: https://ripgrep.datasette.io/-/ripgrep?pattern=%22sqlite-utils%5B%22%3E%5D&glob=setup.py

It would be neat to be able to use this with rga as well. Any plans to add a rga --json flag similar to the one in rg?

@phiresky
Copy link
Owner

phiresky commented Dec 2, 2020

Great idea. In general --json should already work with rga, same as with ripgrep. The only issue is that both the inner filenames (e.g. hello.txt within a .zip file) as well as the line number prefix (e.g. Page XYZ in a pdf) will appear within the search result instead of as metadata in the json object.

Off the top of my head, I'm not sure if this is easily possible to create cleanly since ripgrep doesn't have any method for passing a side-channel of metadata through the preprocessing process.

One method would be to insert the metadata into the results stream directly in rga-preproc, then postprocess the output of rg --json in rga and extract that metadata again. That would be pretty hacky though, so I'm not sure if I'd want to do it.

@phiresky
Copy link
Owner

Potentially the best we could do is to output json-in-json (like {"foo":"{\\"foo\\":\\"bar\\"}"}), because ripgrep itself assumes textual output of the preprocessors. Not very satisfying..

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

No branches or pull requests

2 participants