Skip to content

Commit 753eaad

Browse files
tn0vakzerosnacks
andauthored
Clarify stdJson key syntax (#832)
The `stdJson` docs currently use a generic `<json_path>` placeholder, but the API actually expects the same selector syntax as `vm.parseJson*`. The existing tests already show the real usage with `.a` for a field and `$` for the root object in `test/StdJson.t.sol`, so the current comments are easy to misread. This updates the `StdJson` examples and function docs to match the behavior that is already implemented and tested today. It is a comment-only change with no ABI or runtime impact, just a documentation fix that makes the interface clearer and more accurate. Co-authored-by: zerosnacks <95942363+zerosnacks@users.noreply.github.com>
1 parent e4cc8e2 commit 753eaad

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

src/StdJson.sol

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@ pragma solidity >=0.8.13 <0.9.0;
33

44
import {VmSafe} from "./Vm.sol";
55

6-
// Helpers for parsing and writing JSON files
6+
// Helpers for parsing and writing JSON files.
7+
// `key` parameters use the same selector syntax as the `vm.parseJson*` cheatcodes,
8+
// for example `.a` for a nested field or `$` for the root object.
79
// To parse:
810
// ```
911
// using stdJson for string;
1012
// string memory json = vm.readFile("<some_path>");
11-
// json.readUint("<json_path>");
13+
// uint256 value = json.readUint(".a");
14+
// bytes memory encoded = json.parseRaw("$");
1215
// ```
1316
// To write:
1417
// ```
@@ -23,10 +26,14 @@ import {VmSafe} from "./Vm.sol";
2326
library stdJson {
2427
VmSafe private constant vm = VmSafe(address(uint160(uint256(keccak256("hevm cheat code")))));
2528

29+
/// @dev Returns whether `key` exists in `json`.
30+
/// `key` uses the same selector syntax as `vm.parseJson*`, such as `.a` or `$`.
2631
function keyExists(string memory json, string memory key) internal view returns (bool) {
2732
return vm.keyExistsJson(json, key);
2833
}
2934

35+
/// @dev ABI-encodes the JSON value selected by `key`.
36+
/// `key` uses the same selector syntax as `vm.parseJson*`, such as `.a` or `$`.
3037
function parseRaw(string memory json, string memory key) internal pure returns (bytes memory) {
3138
return vm.parseJson(json, key);
3239
}

0 commit comments

Comments
 (0)