Skip to main content

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

Tries to parse an string into a T type variable. Status: stable
Returns: T

Parameters

NameTypeDescription
targetstringThe target object to be serialized

Example usage

const { tryParse } = Melon.std.json;

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

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

console.log(result);

Extra behaviors

ConditionConsequenceWorkaround
Passing an invalid JSON as argumentAn invalid empty object will be returned ({})Consider using Melon.std.json.tryDeserialize or be sure that no invalid JSON will be passed as argument