Add parseJsonKeys() cheatcode#5252
Conversation
|
Actually, this could have been possible just with usage of something like |
7792fbb to
c208810
Compare
| writeJson(string, string, string) | ||
| parseJson(string)(bytes) | ||
| parseJson(string, string)(bytes) | ||
| parseJsonKeys(string, string)(string[]) |
There was a problem hiding this comment.
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
|
|
||
| let res = value | ||
| .as_object() | ||
| .unwrap() |
There was a problem hiding this comment.
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 |
Evalir
left a comment
There was a problem hiding this comment.
lgtm as soon as we remove the unwraps!
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: