krjson
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

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]
	}
}

Readme

Keywords

none

Package Sidebar

Install

npm i krjson

Weekly Downloads

1

Version

1.0.3

License

ISC

Last publish

Collaborators

  • karikera