Convert API
parseJson()
Trying to parse a JSON string.
- Accepts any single argument.
- Returns the corresponding object, array, string, number, boolean, or null value from the given JSON string.
If the passed argument is an array or object, it will be returned as is, without JSON parsing.
If JSON parsing fails, it will return false.
Example:
parseJson('{"key": "value"}');
// {key: 'value'}
parseJson({key: 'value'});
// {key: 'value'}
parseJson('[1, "book"]');
// [1, 'book']
parseJson({});
// {}
parseJson('book');
// false
parseJson('"book"');
// 'book'
parseJson(10);
// 10
parseJson('true');
// true
parseJson(null);
// null