# json-promise

> Promise based JSON parser. Handles invalid JSON data gracefully.

Latest version **1.1.8** (published 2014-09-02) · MIT license · 0 weekly downloads

## Install

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

## 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.1.8 |
| Published | 2014-09-02 |
| First published | 2014-08-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8 |
| Author | Kirk Gordon |
| Maintainers | krg7880 |
| Keywords | json, parse, stringify, promise |

## Links

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

## Dependencies (1)

- [bluebird](https://npm.io/package/bluebird.md) *

## 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.8 (latest) — 2014-09-02
- 1.0.8 — 2014-08-29
- 1.0.7 — 2014-08-29
- 1.0.6 — 2014-08-29
- 1.0.5 — 2014-08-29
- 1.0.4 — 2014-08-29
- 1.0.3 — 2014-08-29
- 1.0.2 — 2014-08-29
- 1.0.1 — 2014-08-29
- 1.0.0 — 2014-08-29

## README

[![Build Status](https://travis-ci.org/kirk7880/json-promise.svg?branch=master)](https://travis-ci.org/kirk7880/json-promise) [![Coverage Status](https://coveralls.io/repos/kirk7880/json-promise/badge.png?branch=master)](https://coveralls.io/r/kirk7880/json-promise?branch=master)

## Introduction

Parse and stringify JSON data using promise to gracefully 
handle success and failures if the data is invalid. See the
examples below for usage instructions. This module use [bluebird](https://github.com/petkaantonov/bluebird)
for [Promise/A+](http://promisesaplus.com) support.

## Installation
npm install [json-promise](https://www.npmjs.org/package/json-promise)

## Usage Instructions

### Parsing JSON data
```javascript
var json = require('json-promise');
var str = [
	'{"menu":{"id":"file","value":"File","popup":' 
	,'{"menuitem":[{"value":"New","onclick":"CreateNewDoc()"},' 
	,'{"value":"Open","onclick":"OpenDoc()"},{"value":"Close",' 
	,'"onclick":"CloseDoc()"}]}}}'
].join('');

json.parse(str)
	.then(function onParse(obj) {
		// do something with the data object
	})
	.catch(function onParseError(e) {
		// the data is corrupted!
	});
```

### Stringify JSON data
```javascript
var json = require('json-promise');
var obj = {
  "menu": {
    "id": "file",
    "value": "File",
    "popup": {
      "menuitem": [
        {
          "value": "New",
          "onclick": "CreateNewDoc()"
        },
        {
          "value": "Open",
          "onclick": "OpenDoc()"
        },
        {
          "value": "Close",
          "onclick": "CloseDoc()"
        }
      ]
    }
  }
};

json.stringify(obj)
	.then(function onStringify(obj) {
		// do something with the string
	})
	.catch(function onStringifyError(e) {
		// the data is corrupted!
	});
```

### Testing
npm test

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