ddgr icon indicating copy to clipboard operation
ddgr copied to clipboard

FR/Bug: Add the instant answer when using `--json`

Open chrisgrieser opened this issue 1 year ago • 2 comments

Not sure whether it's a bug or intentional, when using --json, the instant answer is left out, resulting in the need to often call ddgr twice to get json output & any instant answer

# shows one result with instant answer
ddgr -n 1 --np ip

# shows only result
ddgr -n 1 --json ip

chrisgrieser avatar Jul 16 '23 19:07 chrisgrieser

Please raise a PR.

jarun avatar Sep 10 '23 04:09 jarun

I'm not really sure what the best way for doing this would be. I have an implementation here:

https://github.com/kometenstaub/ddgr

Diff:

https://github.com/jarun/ddgr/compare/main...kometenstaub:ddgr:main

However, this approach changes the JSON format and would be a breaking change.

The answers from before are still a list, but the return format is a dict.

{
results: [],
instant_answer: "…",
}

instant_answer will not be added to the dict if it is missing.

kometenstaub avatar Oct 04 '23 09:10 kometenstaub