jarun / ddgr

:duck: DuckDuckGo from the terminal
GNU General Public License v3.0
2.92k stars 139 forks source link

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

Closed chrisgrieser closed 6 days ago

chrisgrieser commented 1 year ago

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
jarun commented 12 months ago

Please raise a PR.

kometenstaub commented 11 months ago

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.