New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

safe-json-decode

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

safe-json-decode

A minimal package for encoding and decoding json without unhandled exceptions being thrown on failure

latest
Source
npmnpm
Version
1.1.0
Version published
Maintainers
1
Created
Source

safe-json-decode

safe-json-decode is a minimal package for encoding and decoding json without unhandled exceptions being thrown on failure

Package is bundled using unbuild

Installation

npm i safe-json-decode

In Node.js

// ESM:
import { safeJsonDecode, safeJsonEncode } from 'safe-json-decode';
// CommonJS:
const { safeJsonDecode, safeJsonEncode } = require('safe-json-decode');

Usage

// Same behavior as JSON.parse with valid JSON
safeJsonDecode('{ "foo": "bar" }'); // => {foo: 'bar'}
// Returns null if JSON.parse fails
safeJsonDecode('{ invalid }'); // => null


// Same behavior as JSON.stringify with value that can be serialized
safeJsonEncode({ foo: 'bar' }); // => '{"foo": "bar"}'
// Returns null if JSON.stringify fails
const objectWithCircularReference = {};
objectWithCircularReference.self = objectWithCircularReference;
safeJsonEncode(objectWithCircularReference);


// Handle side effects if error is caught

const handleError = (error) => console.error(error);

safeJsonDecode('{ invalid }', undefined, handleError); 
safeJsonEncode(objectWithCircularReference, undefined, undefined, handleError);

Keywords

ESM

FAQs

Package last updated on 14 Jul 2025

Did you know?

Socket

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.

Install

Related posts