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] Add path and default parameter in .json() #356

Open
perklet opened this issue Jul 24, 2024 · 0 comments
Open

[Feature] Add path and default parameter in .json() #356

perklet opened this issue Jul 24, 2024 · 0 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@perklet
Copy link
Collaborator

perklet commented Jul 24, 2024

Is your feature request related to a problem? Please describe.
It is very common that we only want part of the json response. Using jsonpath, we can directly select the particular part.

Describe the solution you'd like

from curl_cffi import requests

r = requests.get("https://example.com/api/users.json")

# before
try:
    users = r.json()["data"]["users"]
except KeyError:
    users = []

# after
users = r.json(path=".data.users", default=[])

Describe alternatives you've considered
N/A

Additional context
The dependencies should be optional, like pip install curl_cffi[extra].

@perklet perklet added the enhancement New feature or request label Jul 24, 2024
@perklet perklet self-assigned this Jul 24, 2024
@perklet perklet added this to the v0.8 milestone Jul 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant