Skip to content

Instantly share code, notes, and snippets.

@joejordan
Created January 26, 2023 02:34
Show Gist options
  • Save joejordan/a944ba7558b24e0d2f0d7f79f7601fb8 to your computer and use it in GitHub Desktop.
Save joejordan/a944ba7558b24e0d2f0d7f79f7601fb8 to your computer and use it in GitHub Desktop.
Foundry JSON troubles
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.4;
import { Script } from "forge-std/Script.sol";
import { console2 } from "forge-std/console2.sol";
import { stdJson } from "forge-std/StdJson.sol";
contract FileUtils is Script {
using stdJson for string;
function serializeDemo() public {
string memory json = "INTERNAL_KEY";
console2.log(json); // output: INTERNAL_KEY
json.serialize("address1", address(1));
console2.log(json); // output: INTERNAL_KEY
json = json.serialize("address2", address(2));
console2.log(json); // output: {"address2":"0x0000000000000000000000000000000000000002","address1":"0x0000000000000000000000000000000000000001"}
json = json.serialize("address3", address(3));
console2.log(json); // output: {"address3":"0x0000000000000000000000000000000000000003"}
// shouldn't the above output include all three address entries?
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment