const apiPayload: MutableJsonValue = {
user: {
name: "John Doe",
age: 30,
preferences: ["dark-mode", "notifications"]
}
};
// Can modify the structure
if (typeof apiPayload === 'object' && apiPayload !== null && 'user' in apiPayload) {
const user = apiPayload.user as MutableJsonValue;
if (typeof user === 'object' && user !== null && 'age' in user) {
(user as any).age = 31; // Update age
}
}
Represents any valid JSON value that can be modified after creation. This includes primitives, mutable arrays of JSON values, or mutable objects where keys are strings and values are JSON values.
Use this type when you need to build, modify, or manipulate JSON structures programmatically, such as constructing API payloads or transforming data.