json-from-script
Tiny JSON parser for your Content Security Policy aware script tags.
Installation
$ npm install --save json-from-script
Usage
When your HTML contains any script tag like this;
You can parse it in your Javascript application like this;
; // Parsed will be { foo: { bar: 'baz' } }const parsed = ;
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