Socket
Socket
Sign inDemoInstall

is-json

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

is-json - npm Package Compare versions

Comparing version 1.1.3 to 1.1.4

22

index.js

@@ -1,2 +0,1 @@

function isString (x) {

@@ -19,8 +18,17 @@ var type = Object.prototype.toString.apply(x);

// https://github.com/douglascrockford/JSON-js/blob/master/json2.js#L451
return /^[\],:{}\s]*$/
.test(str
.replace(/\\["\\\/bfnrtu]/g, '@')
.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']')
.replace(/(?:^|:|,)(?:\s*\[)+/g, ''));
if (/^\{(.*?)\}$/.test(str))
return /"(.*?)":(.*?)/g.test(str);
if (/\[(.*?)\]/.test(str)) {
str = str.replace(/\s/g, '')
.replace(/^\[/, '')
.replace(/\]$/, '')
.replace(/},{/g, '}\n{')
.split(/\n/);
console.log(str);
return str.map(function (s) { return isJSON(s); })
.reduce(function (prev, curr) { return !!curr; });
}
return false;
}
{
"name": "is-json",
"version": "1.1.3",
"version": "1.1.4",
"description": "check if a string is a valid JSON string without using Try/Catch",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -6,3 +6,3 @@ var test = require('tape');

test('performe isJSON verifications', function (t) {
t.plan(10);
t.plan(14);

@@ -21,2 +21,7 @@ t.deepEqual(isJSON(null), false, '`null`, should return false');

'`{"a":"obja","b":[0,1,2],"c":{"d":"some object"}}`, should return true');
t.deepEqual(isJSON('1,2,3'), false, '`1,2,3`, should return false');
t.deepEqual(isJSON('{1,2,3}'), false, '`{1,2,3}`, should return false');
t.deepEqual(isJSON('[{"a": 123}, {1,2,3}}]'), false, '`[{"a": 123, {1,2,3}}]`, should return false');
t.deepEqual(isJSON('[{"a": {"aa": [1,2,3,4], "aaa": {"d": 1212}}}, {"b": "test", "c": [1,2,3]}]'),
true, 'complex object should return true');
});
SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc