Skip to content

Add pure JSON serialization cheatcodes  #5764

@vdrg

Description

@vdrg

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

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Next Up

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions