Security News
NIST Misses 2024 Deadline to Clear NVD Backlog
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
@bugsnag/safe-json-stringify
Advanced tools
@bugsnag/safe-json-stringify is a utility for safely converting JavaScript objects to JSON strings. It is designed to handle circular references and other issues that can cause JSON.stringify to throw errors.
Safe JSON Stringify
This feature allows you to safely stringify objects that contain circular references. The code sample demonstrates how to use the package to stringify an object with a circular reference without causing an error.
{"example":"const safeJsonStringify = require('@bugsnag/safe-json-stringify');\nconst obj = { name: 'Alice' };\nobj.self = obj;\nconst jsonString = safeJsonStringify(obj);\nconsole.log(jsonString);"}
circular-json is another package that handles circular references in JSON objects. It provides similar functionality to @bugsnag/safe-json-stringify by allowing you to stringify objects with circular references without throwing errors.
flatted is a package that offers a way to serialize and deserialize JavaScript objects containing circular references. It uses a different approach compared to @bugsnag/safe-json-stringify, focusing on a more compact representation of the circular references.
json-stringify-safe is a package that provides a drop-in replacement for JSON.stringify, handling circular references by replacing them with a placeholder. It is similar to @bugsnag/safe-json-stringify in its goal to prevent errors during stringification.
This is a fork of safe-json-stringify
with some opinionated changes, specifically for Bugsnag's use-case:
...
in such circumstances.npm install @bugsnag/safe-json-stringify
The API is the same as JSON.stringify
, with an additional options
object:
stringify(obj, [optional replacer], [optional spaces], [options])
options.filterKeys
: a list of keys whose value should be replaced with the string [FILTERED]
. Keys can be strings for exact matches, or regexes for partial or pattern matches. The array can contain a mixture of both.options.filterPaths
: a list of paths where the filterKeys
option will be applied. The format of these strings are key names separated by .
and if the property is an array, it is represented with []
. For example: events.[].metaData
.var stringify = require('@bugsnag/safe-json-stringify')
stringify({
api_key: 'd145b8e5afb56516423bc4d605e45442',
events: [
{
errorMessage: 'Failed load tickets',
errorClass: 'CheckoutError',
user: {
name: 'Jim Bug',
email: 'jim@bugsnag.com',
api_key: '245b39ebd3cd3992e85bffc81c045924'
}
}
]
}, null, 2, {
filterKeys: [ 'api_key' ],
filterPaths: [ 'events.[].user' ]
})
// yields the following json:
// {
// "api_key": "d145b8e5afb56516423bc4d605e45442",
// "events": [
// {
// "errorMessage": "Failed load tickets",
// "errorClass": "CheckoutError",
// "user": {
// "name": "Jim Bug",
// "email": "jim@bugsnag.com",
// "api_key": "[FILTERED]"
// }
// }
// ]
// }
The original code is licensed with MIT, and so are the modifications.
The MIT License (MIT)
Copyright (c) 2014-2018 Debitoor, Bugsnag
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
Prevent defined property getters from throwing errors
We found that @bugsnag/safe-json-stringify demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 10 open source maintainers 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.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
Security News
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.