Research
Recent Trends in Malicious Packages Targeting Discord
The Socket research team breaks down a sampling of malicious packages that download and execute files, among other suspicious behaviors, targeting the popular Discord platform.
json-parse-better-errors
Advanced tools
Package description
The json-parse-better-errors package is designed to provide more informative error messages when parsing JSON strings in JavaScript. This can be particularly useful in development environments where understanding the source of a JSON parsing error quickly is crucial. It wraps the standard JSON.parse method to catch errors and rethrow them with enhanced messages, indicating the exact position and nature of the syntax issue.
Enhanced JSON parsing error messages
This feature enhances the error messages returned by the JSON.parse method. In the code sample, an attempt is made to parse an invalid JSON string. The json-parse-better-errors package catches the syntax error and provides a more informative error message, including the position of the error within the string.
"use strict";
const parseJson = require('json-parse-better-errors');
try {
const obj = parseJson('{"foo": 1,}');
} catch (e) {
console.error(e.message);
}
This package offers a way to safely parse JSON strings without throwing an exception on invalid JSON. It returns an object with an error and value property, allowing the user to handle errors more gracefully. Compared to json-parse-better-errors, it focuses more on safe parsing with a different error handling approach rather than enhancing error messages.
Similar to fast-json-parse, safe-json-parse provides a safe way to parse JSON strings, returning a tuple with an error and the parsed object. It's designed to avoid try-catch blocks for JSON parsing. While it also focuses on error handling, it doesn't enhance the error messages like json-parse-better-errors does.
Changelog
Readme
json-parse-better-errors
is a Node.js library for managing
local key and content address caches. It's really fast, really good at
concurrency, and it will never give you corrupted data, even if cache files
get corrupted or manipulated.
It was originally written to be used as npm's local cache, but can just as easily be used on its own
Translations: español
$ npm install --save json-parse-better-errors
const parseJson = require('json-parse-better-errors')
parseJson('"foo"')
parseJson('garbage') // more useful error message
The json-parse-better-errors team enthusiastically welcomes contributions and project participation! There's a bunch of things you can do if you want to contribute! The Contributor Guide has all the information you need for everything from reporting bugs to contributing entire new features. Please don't hesitate to jump in if you'd like to, or even ask us questions if something isn't clear.
All participants and maintainers in this project are expected to follow Code of Conduct, and just generally be excellent to each other.
Please refer to the Changelog for project history details, too.
Happy hacking!
> parse(txt, ?reviver, ?context=20)
Works just like JSON.parse
, but will include a bit more information when an
error happens.
FAQs
JSON.parse with context information on error
The npm package json-parse-better-errors receives a total of 11,324,255 weekly downloads. As such, json-parse-better-errors popularity was classified as popular.
We found that json-parse-better-errors demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
The Socket research team breaks down a sampling of malicious packages that download and execute files, among other suspicious behaviors, targeting the popular Discord platform.
Security News
Socket CEO Feross Aboukhadijeh joins a16z partners to discuss how modern, sophisticated supply chain attacks require AI-driven defenses and explore the challenges and solutions in leveraging AI for threat detection early in the development life cycle.
Security News
NIST's new AI Risk Management Framework aims to enhance the security and reliability of generative AI systems and address the unique challenges of malicious AI exploits.