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

Unpack default value if key missing #621

Open
Zer0-One opened this issue Jul 19, 2022 · 2 comments
Open

Unpack default value if key missing #621

Zer0-One opened this issue Jul 19, 2022 · 2 comments

Comments

@Zer0-One
Copy link

A feature that I would find useful at the moment is the ability to unpack a given default value when the specified key is missing. You could add a double ? as a format specifier, and then expect two arguments instead of one, the second being the default to "unpack" instead of the missing value.

Something like this:
int unpk = json_unpack_ex(my_object, &error, 0, "{s??i}", "foo", 42, &i);

@akheron
Copy link
Owner

akheron commented Aug 9, 2022

This sounds like a useful feature, although using a single character that's something else than ? might be easier implementation-wise.

Would you be interested in implementing this?

@Zer0-One
Copy link
Author

Zer0-One commented Aug 9, 2022

I'm taking a look at it. Having a bit of trouble wrapping my head around the code, but I'll get back to you on that.

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