Extract JSON From HTML Using JavaScript – Temme

Category: Javascript , Recommended | February 11, 2018
Author: shinima
Views Total: 67
Official Page: Go to website
Last Update: February 11, 2018
License: MIT

Preview:

Extract JSON From HTML Using JavaScript  – Temme

Description:

The Temme JavaScript library uses custom selectors to extract JSON from HTML using pure JavaScript.

How to use it:

Install the Temme library:

# Yarn
$ yarn add temme

# NPM
$ npm install temme --save

Import the Temme library.

// ES 6
import temme from 'temme';

// CommonJS:
const temme = require('temme');

Specify the selector.

const selector = 'div[color=$c]{$t};'

Define the HTML.

const html = '<div color="red">hello world</div>'

Extract JSON from HTML:

temme(html, selector)

This will output a JSON array:

{ c: 'red', t: 'hello world' }

Leave a Reply