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

json-alexander

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-alexander

Serenity Now! Safely parse JSON

  • 0.0.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6.8K
decreased by-25.79%
Maintainers
1
Weekly downloads
 
Created
Source

Friendly JSON Parse

Serenity now! Safe JSON.parse

import parseJSON from 'json-alexander'

/* Normal Valid JSON */
parseJSON('{"valid": "works"}')
// -> {"valid": "works"}

/* Javascript objects */
parseJSON({ key: 'val' })
// -> { key: 'val' }

/* Malformed JSON */
parseJSON("{'malformed': 'works'}")
// -> {"malformed": "works"}

/* Unbalanced JSON */
parseJSON('{"unbalanced": "object"')
// -> {"unbalanced": "object" }

Returns undefined if value passed in is not parsable

Other options

  • https://github.com/hua1995116/easy-json-parse
  • https://github.com/RyanMarcus/dirty-json
  • https://www.npmjs.com/package/try-json

Security concerns

This package makes use of regular expressions when fixing malformed json. As a result, it may be vulnerable to a REDOS attack.

I've run the regex patterns through vuln-regex-detector and the patterns used appear to be safe.

I'm leveraging this in Serverless Functions with max timeouts on requests, so redos is somewhat mitigated. If using in long running server... use at your own risk.

Use simple parser if you want to ignore malformed JSON & disable the mechanism that leverage regex patterns.

import { simple as simpleParse } from 'json-alexander'

/* Normal Valid JSON */
simpleParse('{"valid": "works"}')
// -> {"valid": "works"}

/* Javascript objects */
simpleParse({ key: 'val' })
// -> { key: 'val' }

/* Malformed JSON */
simpleParse("{'malformed': 'works'}")
// -> null no autofix

FAQs

Package last updated on 13 Sep 2019

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