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 parse-json
16 const parseJson = require('parse-json');
17 const 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 in foo.json:3:1
45 // You can also add the filename at a later point
49 err.fileName = 'foo.json';
53 JSONError: Trailing comma in object in foo.json:3:1
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](https://sindresorhus.com)