How to use Lodash _.isJSON() Method In Javascript

In Lodash _.isJSON() Method approach, we are using Lodash _.isJSON() method that returns the boolean value that is true if the passes value is a JSON string else it returns false.

Example: In this example, we are using the Lodash _.isJSON() method.

Javascript
// Defining lodash contrib variable 
let _ = require('lodash-contrib'); 

// Checking for _.isJSON() method
console.log("The Value is JSON : " +_.isJSON( 
'{"w3wiki" : "A Computer Science portal for Geeks"}'));

Output:

The Value is JSON : true

Check if a string is a valid JSON string using JavaScript

We will be given a string and we need to validate whether the given string is a valid JSON string or not. JSON string is the same as a javaScript object and it must follow the syntax of that object. If the syntax is correct then we have to return true or we have to return false.

Methods to Check if a String is Valid JSON String:

Table of Content

  • Method 1: Using JSON.parse() method
  • Method 2: Using JSON.stringify() method
  • Method 3: Using Lodash _.isJSON() Method
  • Method 4: Using Regular Expression

Similar Reads

Method 1: Using JSON.parse() method

The  JSON.parse() method in JavaScript is used to parse a JSON string which is written in a JSON format and returns a JavaScript object....

Method 2: Using JSON.stringify() method

The JSON.stringify() method in Javascript is used to create a JSON string out of it....

Method 3: Using Lodash _.isJSON() Method

In Lodash _.isJSON() Method approach, we are using Lodash _.isJSON() method that returns the boolean value that is true if the passes value is a JSON string else it returns false....

Method 4: Using Regular Expression

Regular expressions can also be used to validate JSON strings....