# Parse JSON > Parse a string as [JSON][json].
## Usage ```javascript var parseJSON = require( '@stdlib/utils/parse-json' ); ``` #### parseJSON( str\[, reviver] ) Parses a `string` as [JSON][json]. ```javascript var out = parseJSON( '{"beep":"boop"}' ); // returns {'beep':'boop'} ``` If unable to parse a `string` as [JSON][json], the function returns an error. ```javascript var out = parseJSON( 'beep' ); // returns ``` To transform the `string` being parsed, provide a `reviver`. ```javascript function reviver( key, value ) { if ( key === '' ) { return value; } if ( key === 'beep' ) { return value; } } var str = '{"beep":"boop","a":"b"}'; var out = parseJSON( str, reviver ); // returns {'beep':'boop'} ```
## Notes - In contrast to the native [`JSON.parse()`][json-parse], this implementation throws a `TypeError` if provided **any** value which is not a `string`. ```javascript var out = JSON.parse( null ); // returns null out = parseJSON( null ); // throws ``` - In contrast to the native [`JSON.parse()`][json-parse], this implementation does **not** throw a `SyntaxError` if unable to parse a `string` as [JSON][json]. ```javascript var out = parseJSON( '{"beep":"boop}' ); // returns out = JSON.parse( '{"beep":"boop}' ); // throws ``` - In contrast to the native [`JSON.parse()`][json-parse], this implementation throws a `TypeError` if provided a `reviver` argument which is **not** a `function`. ```javascript var out = JSON.parse( '{"a":"b"}', [] ); // returns {'a':'b'} out = parseJSON( '{"a":"b"}', [] ); // throws ```
## Examples ```javascript var parseJSON = require( '@stdlib/utils/parse-json' ); var out; out = parseJSON( '{"beep":"boop"}' ); // returns {'beep':'boop'} out = parseJSON( '3.14' ); // returns 3.14 out = parseJSON( 'true' ); // returns true out = parseJSON( 'null' ); // returns null out = parseJSON( '{"beep":"boop}' ); // returns ```