-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Add parseJsonKeys() cheatcode #5252
Add parseJsonKeys() cheatcode #5252
Conversation
Actually, this could have been possible just with usage of something like |
7792fbb
to
c208810
Compare
@@ -180,6 +180,7 @@ writeJson(string, string) | |||
writeJson(string, string, string) | |||
parseJson(string)(bytes) | |||
parseJson(string, string)(bytes) | |||
parseJsonKeys(string, string)(string[]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we add a parseJsonKeys(string)(string[])
to parse the root keys? might be better UX than passing $
as the key, but I don't do tons of jsonpath stuff so maybe $
is common/standardized and we should stick with just that?
0d9664b
to
d650008
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hey! sorry for the delay on this, looks great. just a nit! also need to resolve conflicts
|
||
let res = value | ||
.as_object() | ||
.unwrap() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use ?
instead of unwrapping here so we don't panic
d650008
to
d4a10cd
Compare
hey @Evalir I have pushed resolved conflicts regarding |
hey hey @klkvr coming back to this—yes ideally! even if it's a guarantee it's best to not introduce any panicking. feel free to use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm as soon as we remove the unwrap
s!
d4a10cd
to
d5606b2
Compare
hey @Evalir rebased from master and removed unwrap |
Thank you! Let's add docs for this on the book & forge-std pr @klkvr |
Motivation
Currently there is no way (or at least I didn't find one) to get keys of a JSON object
Solution
Create new cheatcode
parseJsonKeys(string calldata json, string calldata key)
Examples: