🚀 DAY 5 OF LAUNCH WEEK:Introducing Webhook Events for Alert Changes.Learn more →
Socket
Book a DemoInstallSign in
Socket

json-from-script

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-from-script

Tiny JSON parser for your CSP aware script tags

latest
Source
npmnpm
Version
3.1.0
Version published
Weekly downloads
42
-87.31%
Maintainers
1
Weekly downloads
 
Created
Source

json-from-script

A tiny (276B) JSON parser for your Content Security Policy aware script tags.

NPM version Build Status licenses

Installation

$ npm install --save json-from-script

Usage

When your HTML contains any script tag like this;

<script type="application/json" class="data" data-attr="foo">{&quot;bar&quot;:&quot;baz&quot;}</script>

You can parse it in your Javascript application like this;

import jsonFromScript from 'json-from-script';

// Parsed will be { foo: { bar: 'baz' } }
const parsed = jsonFromScript();

API

jsonFromScript(selector, attribute)

Creates a new instance of the parser with the given options. The following options can alternatively be provided to configure the parser for your specific needs:

  • selector <String>: The selector for the script tags to parse. (default: script.data)
  • attribute <String>: The data attribute to use when setting the attribute on the parsed object. (default: data-attr)

License

MIT © Robin van der Vleuten

FAQs

Package last updated on 18 Sep 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