# htmlescape

> Properly escape JSON for usage as an object literal inside of a `` tag

Latest version **1.1.1** (published 2016-03-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install htmlescape
pnpm add htmlescape
yarn add htmlescape
bun add htmlescape
```

## Health

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

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.1 |
| Published | 2016-03-23 |
| First published | 2014-09-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/htmlescape) |
| Module format | CommonJS |
| Node | >=0.10 |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 42 |
| Author | Andres Suarez |
| Maintainers | zertosh |
| Keywords | escape, encoding, html, json, template |

## Links

- npm: https://www.npmjs.com/package/htmlescape
- Repository: https://github.com/zertosh/htmlescape
- Issues: https://github.com/zertosh/htmlescape/issues
- npm.io page: https://npm.io/package/htmlescape

## 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.1.1 (latest) — 2016-03-23
- 1.1.0 — 2015-04-12
- 1.0.0 — 2014-09-28
- 0.0.1 — 2014-09-28

## README

# htmlescape

Properly escape JSON for usage as an object literal inside of a `<script>` tag. Use `htmlescape` in place of `JSON.stringify`. For more info see [JSON: The JavaScript subset that isn't](http://timelessrepo.com/json-isnt-a-javascript-subset).

## Transformations

| from     | to        |
| -------- |:---------:|
| `&`      | `\\u0026` |
| `>`      | `\\u003e` |
| `<`      | `\\u003c` |
| `\u2028` | `\\u2028` |
| `\u2029` | `\\u2029` |


## Usage

```js
var htmlescape = require('htmlescape');
htmlescape({prop:'value'});
//=> '{"prop":"value"}'
```

Or in your templates:

```html
<script>
var payload = <%= htmlescape(payload) %>;
</script>
```

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