krjson
v1.0.3
Published
```javascript
Downloads
4
Readme
krjson
const { parseJson, indexToLine } = require('krjson');
try
{
parseJson('{\nerror:json\n}');
}
catch (err)
{
console.log(err.message); // [message] JSON at line [line], column [column];
console.log(err.line); // [line]
console.log(err.column); // [column]
}
try
{
JSON.parse('{\nerror:json\n}');
}
catch (err)
{
const regexp = /^(.+) JSON at position ([0-9]+)$/;
if (regexp.test(err.message))
{
const index = +RegExp.$2;
const {line, column} = indexToLine(text, index);
console.log(line); // [line]
console.log(column); // [column]
}
}