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.5 to 1.2.5

10

index.js

@@ -12,2 +12,3 @@ function isString (x) {

module.exports = isJSON;
isJSON.strict = strict;

@@ -35,1 +36,10 @@ function isJSON (str, pass_object) {

}
function strict (str) {
try {
return JSON.parse(str) && true;
} catch (ex) {
return false;
}
}

2

package.json
{
"name": "is-json",
"version": "1.1.5",
"version": "1.2.5",
"description": "check if a string is a valid JSON string without using Try/Catch",

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

@@ -12,3 +12,3 @@ # is-json

**V1.1**
**V1.2**

@@ -38,2 +38,6 @@

console.log(isJSON(object, true)); // true
console.log(isJSON(object, true)); // true
// can use isJSON.strict (uses try/catch) if wants something more robust
console.log(isJSON.strict('{\n "config": 123,\n "test": "abcde" \n}')); // true

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

test('performe isJSON verifications', function (t) {
t.plan(15);
t.plan(16);

@@ -24,5 +24,6 @@ t.deepEqual(isJSON(null), false, '`null`, should return false');

t.deepEqual(isJSON('[{"a": 123}, {1,2,3}}]'), false, '`[{"a": 123, {1,2,3}}]`, should return false');
var cobj = '[{"a": {"aa": [1,2,3,4], "aaa": {"d": 1212}}}, {"b": "test", "c": [1,2,3], "date": "' + new Date() + '"}]';
var cobj = '[{"a": {"aa": [1,2,3,4], "aaa": {"d": 1212}}}, {"b": "test", "c": [1,2,3], "date": "' + new Date() + '}]';
t.deepEqual(isJSON(cobj), true, cobj + ', should return true');
t.deepEqual(isJSON(new Date()), false, '`Date`, should return false');
t.deepEqual(isJSON.strict('{\n "config": 123,\n "test": "abcde" \n}'), true, '`{\n "config": 123,\n "test": "abcde" \n}`, 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