Socket
Book a DemoInstallSign in
Socket

base64tojson

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

base64tojson

Decodes a Base64-encoded JSON string into a JavaScript object

latest
npmnpm
Version
1.0.2
Version published
Maintainers
1
Created
Source

📄 base64tojson

Decode a Base64-encoded JSON string into a JavaScript object.

Perfect for decoding API payloads, tokens, or embedded data.

📦 Installation

Using npm

npm install base64tojson

Using yarn

yarn add base64tojson

🚀 Usage

const base64tojson = require("base64tojson");

(async () => {
  const jsonData = { name: "Yunus", age: 28 };

  const base64 = Buffer.from(JSON.stringify(jsonData)).toString("base64");

  try {
    const result = await base64tojson(base64);
    console.log(result); // { name: 'Yunus', age: 28 }
  } catch (err) {
    console.error("Invalid base64 or JSON:", err);
  }
})();

⚙️ Options

This function takes a single Base64-encoded string. No options object required.

ParameterTypeRequiredDescription
base64DatastringA Base64-encoded string of a JSON blob

🧾 Output

If successful, it returns a JavaScript object parsed from the JSON content.

If invalid Base64 or JSON, it throws an error.

🧪 Run Test

node test.js

🪪 License

MIT

Keywords

base64

FAQs

Package last updated on 28 Mar 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