Skip to main content

Melon.std.json.deserialize<T>(target)

Deserializes a string into an object of type T. Status: unstable
Returns: T

Parameters

NameTypeDescription
targetstringThe target object to be deserialized

Example usage

const { deserialize } = Melon.std.json;

interface User {
name: string;
surname: string;
}

const userJson = `{name: "John", surname: "Doe"}`;
const result = deserialize<User>(userJson);

console.log(result);

Extra behaviors

ConditionConsequenceWorkaround
There is no error handlingAn invalid empty object will be returned ({})Consider using Melon.std.json.tryDeserialize or be sure that no invalid JSON will be passed as argument