repl.txt (1017B)
1 2 {{alias}}( str[, reviver] ) 3 Attempts to parse a string as JSON. 4 5 Function behavior differs from `JSON.parse()` as follows: 6 7 - throws a `TypeError` if provided any value which is not a string. 8 - throws a `TypeError` if provided a `reviver` argument which is not a 9 function. 10 - returns, rather than throws, a `SyntaxError` if unable to parse a string 11 as JSON. 12 13 Parameters 14 ---------- 15 str: string 16 String to parse. 17 18 reviver: Function (optional) 19 Transformation function. 20 21 Returns 22 ------- 23 out: any|Error 24 Parsed value or an error. 25 26 Examples 27 -------- 28 > var obj = {{alias}}( '{"beep":"boop"}' ) 29 { 'beep': 'boop' } 30 31 // Provide a reviver: 32 > function reviver( key, value ) { 33 ... if ( key === '' ) { return value; } 34 ... if ( key === 'beep' ) { return value; } 35 ... }; 36 > var str = '{"beep":"boop","a":"b"}'; 37 > var out = {{alias}}( str, reviver ) 38 { 'beep': 'boop' } 39 40 See Also 41 -------- 42