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]
}
}
krjson
1.0.3 • Public • PublishedReadme
Keywords
nonePackage Sidebar
Install
npm i krjson
Weekly Downloads
1
Version
1.0.3
License
ISC