JSON.parse() has an optional second parameter meant for a "reviver" function. This function will receive all keys and values from the parsed string, so you can do modifications to the result. This is useful, for example, to convert date strings to objects automatically.

For example:

JSON.parse('{"date":"2018-01-30T16:12:00.000Z"}', function(key, value) {
    if (key === "date")
        return new Date(value);
    return value;
});

This works recursively and on arrays as well; the function will receive every key (ints for arrays) and value (values can be of any type, including whole objects).

Latest on JavaScript
Mastodon Mastodon