-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Description
Component
Forge
Describe the feature you would like
Hi everyone!
The current approach to handling JSON feels somewhat suboptimal. Working with the id -> json map feels like an extra step, which, in my opinion, isn't entirely necessary. If the JSON serialization methods were made "pure", they could operate directly on a JSON string, which has the advantages of not modifying state and being more intuitive.
Consider the current method:
string memory id = "myObj";
vm.serializeString(id, ".foo", "bar");
vm.serializeString(id, ".hello", "world");
string memory json = vm.serializeUint(id, ".someUint", 123);With a direct JSON string approach, it could be simplified to:
string memory json = '{ "foo": "bar" }';
json = vm.serializeString(json, ".hello", "world");
json = vm.serializeUint(json, ".someUint", 123);This method offers more clarity in the way we work with JSON. Also, by the convention used by forge-std, in this case the functions could be declared as pure. Of course this would break a lot of things... an alternative would be to add these as new methods (not ideal as the vm interface is already pretty big).
Thoughts?
Additional context
No response
Metadata
Metadata
Assignees
Labels
Type
Projects
Status