Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

json-parse

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-parse

Curried function that calls `JSON.parse` on provided input returning either the parsed JSON or the specified default value if the data fails to parse as valid JSON instead of throwing a `SyntaxError`.

  • 1.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

json-parse

Curried function that calls JSON.parse on provided input returning either the parsed JSON or the specified default value if the data fails to parse as valid JSON instead of throwing a SyntaxError.

Build Status Code Climate js-standard-style

npm install json-parse --save

You can also use Duo, Bower or download the files manually.

npm stats

npm NPM downloads David

Overview

Similar to try { return JSON.parse } … but more functional and compositionally friendly.

API Example

Basic
var parse = require('json-parse')

parse([])('[1,2,3]')
//=> [ 1, 2, 3 ]

parse([])('[1,2,3')
//=> []
Pointfree Style
var parse = require('json-parse')

Promise.resolve('[1,2,3]')
.then(parse([]))
.then(sum)
//=> 6

Promise.resolve(undefined)
.then(parse([]))
.then(sum)
//=> 0

API

parse(defaultValue, data)

arguments
  • defaultValue (*) Default value to return if given data does not parse as valid JSON.
  • data (*) Data to parse as JSON.
returns
  • (*) JavaScript value corresponding to parsed data.

Alternatives

Contributing

SEE: contributing.md

Licenses

GitHub license

Keywords

FAQs

Package last updated on 23 Jan 2016

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