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

feat: JSON + TOML Parsing with Default Fallbacks #7052

Open
Tracked by #3801
mds1 opened this issue Feb 8, 2024 · 1 comment
Open
Tracked by #3801

feat: JSON + TOML Parsing with Default Fallbacks #7052

mds1 opened this issue Feb 8, 2024 · 1 comment
Labels
A-cheatcodes Area: cheatcodes C-forge Command: forge T-feature Type: feature

Comments

@mds1
Copy link
Collaborator

mds1 commented Feb 8, 2024

Component

Forge

Describe the feature you would like

Ref #8900:

It would be really convenient to be able to set default values in the JSON parsing helpers with a third argument that return the default value when the key is not present in the passed in JSON string.

An example:

readBytes32(string memory json, string memory key, bytes32 default);

This would be similar to the UX of vm.envOr which reads an env var and then returns the default value if it doesn't exist. I am not particular about using overloading or following the Or suffix naming scheme. This would prevent parsing errors for when keys are not present in the JSON. I think it could be implemented by wrapping the low level vm JSON calls with try/catch

To facilitate #3782, we'll first add these overloads as native cheats first, then updating StdJson.sol in forge-std to have the appropriate read* wrapper methods

cc @tynes

Additional context

No response

@mds1 mds1 added the T-feature Type: feature label Feb 8, 2024
@gakonst gakonst added this to Foundry Feb 8, 2024
@github-project-automation github-project-automation bot moved this to Todo in Foundry Feb 8, 2024
@zerosnacks
Copy link
Member

For future reference, this request would include adding the appropriate mirror functions for TOML so feature parity is maintained.

@zerosnacks zerosnacks changed the title feat: JSON Parsing with Default Fallbacks feat: JSON + TOML Parsing with Default Fallbacks Mar 8, 2024
@zerosnacks zerosnacks added A-cheatcodes Area: cheatcodes C-forge Command: forge labels Jul 11, 2024
@zerosnacks zerosnacks added this to the v1.0.0 milestone Jul 26, 2024
@grandizzy grandizzy removed this from the v1.0.0 milestone Oct 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-cheatcodes Area: cheatcodes C-forge Command: forge T-feature Type: feature
Projects
Status: Todo
Development

No branches or pull requests

3 participants