1 # parse-json [![Build Status](https://travis-ci.org/sindresorhus/parse-json.svg?branch=master)](https://travis-ci.org/sindresorhus/parse-json)
3 > Parse JSON with more helpful errors
9 $ npm install --save parse-json
16 var parseJson = require('parse-json');
17 var json = '{\n\t"foo": true,\n}';
25 SyntaxError: Unexpected token }
31 JSONError: Trailing comma in object at 3:1
37 parseJson(json, 'foo.json');
39 JSONError: Trailing comma in object at 3:1 in foo.json
45 // you can also add the filename at a later point
49 err.fileName = 'foo.json';
53 JSONError: Trailing comma in object at 3:1 in foo.json
61 ### parseJson(input, [reviver], [filename])
71 Prescribes how the value originally produced by parsing is transformed, before being returned. See [`JSON.parse` docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#Using_the_reviver_parameter
78 Filename displayed in the error message.
83 MIT © [Sindre Sorhus](http://sindresorhus.com)