New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

json-promise

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-promise

Promise based JSON parser. Handles invalid JSON data gracefully.

  • 1.1.8
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Build Status Coverage Status

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 for Promise/A+ support.

Installation

npm install json-promise

Usage Instructions

Parsing JSON data

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

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

Keywords

FAQs

Package last updated on 02 Sep 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc