# html-json

> Convert HTML to JSON

Latest version **1.0.2** (published 2015-01-21) · ISC license · 0 weekly downloads

## Install

```sh
npm install html-json
pnpm add html-json
yarn add html-json
bun add html-json
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2015-01-21 |
| First published | 2015-01-20 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | RogerHo |
| Maintainers | rogerhokp |
| Keywords | JSON, HTML, HTML to JSON, HTML parser, parse HTML |

## Links

- npm: https://www.npmjs.com/package/html-json
- Repository: https://github.com/rogerhokp/html-json
- Issues: https://github.com/rogerhokp/html-json/issues
- npm.io page: https://npm.io/package/html-json

## Dependencies (1)

- [cheerio](https://npm.io/package/cheerio.md) ^0.18.0

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.0.2 (latest) — 2015-01-21
- 1.0.1 — 2015-01-20
- 1.0.0 — 2015-01-20

## README

#html-json

Simple helper to convert HTML content to JSON

#Usage
 
- Query sytna based on cherrio https://github.com/cheeriojs/cheerio 

###Simple query###
```
  json = require('html-json')(pageContent).extract({
    'title' : title: 'div.container > h1' // by default to get text 
  });
  
  //result 
  {
    'title' : 'Testing'
  }
```

###Function###
```
  json = require('html-json')(pageContent).extract({
    author_page_uri: function($body) {
        return $body.find('div.container > div > a').attr('href').trim();
    }
  });
  
  //result 
  {
    'author_page_uri' : '/data?post=1'
  }
```



###LIST###
```
  json = require('html-json')(pageContent).extract({
    author_page_uri: function($body) {
      images: {
          'PARENT' : '#thumbnail > div.each_box > div > ul img',
          'LIST' : {
              '348px' : function($image){
                  return $image.attr('src');
              },
              '600px' : function($image){
                  return $image.attr('src').replace('&w=348&h=348', '&w=600&h=600');
              }
          }
      }
    }
  });
  
  //result 
  {
    'images' : [
      {
        '348px' : 'http://image.image/image1.jpg&w=348&h=348'
        '600px' : 'http://image.image/image1.jpg&w=600&h=600'
      },
      {
        '348px' : 'http://image.image/image2.jpg&w=348&h=348'
        '600px' : 'http://image.image/image2.jpg&w=600&h=600'
      }
    ]
  }
```



###OBJECT###
```
  json = require('html-json')(pageContent).extract({
    author_page_uri: function($body) {
      'cover': {
        'PARENT' : ' #M201106_0_getTakelook_P00a400040052 > img',
        'OBJECT' : {
            'alt' : function($image){
                return $image.attr('alt');
            },
            'url' : function($image){
                return $image.attr('src');
            } 
        }
      }
    }
  });
  
  //result 
  {
    'cover' : {
      'alt' : 'this is cover',
      'url' : 'http://xxxxxxx'
    }
  }
```

More example please reference `test/test.js`

---
_Source: https://npm.io/package/html-json · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
