foundry_cheatcodes::json

Function serialize_json

Source
fn serialize_json(
    state: &mut Cheatcodes,
    object_key: &str,
    value_key: &str,
    value: DynSolValue,
) -> Result
Expand description

Serializes a key:value pair to a specific object. If the key is valueKey, the value is expected to be an object, which will be set as the root object for the provided object key, overriding the whole root object if the object key already exists. By calling this function multiple times, the user can serialize multiple KV pairs to the same object. The value can be of any type, even a new object in itself. The function will return a stringified version of the object, so that the user can use that as a value to a new invocation of the same function with a new object key. This enables the user to reuse the same function to crate arbitrarily complex object structures (JSON).