Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript check if string is json parsable

var isJsonParsable = string => {
    try {
        JSON.parse(string);
    } catch (e) {
        return false;
    }
    return true;
}
Comment

check if string is json parsable

if (/^[],:{}s]*$/.test(text.replace(/["/bfnrtu]/g, '@').
replace(/"[^"

]*"|true|false|null|-?d+(?:.d*)?(?:[eE][+-]?d+)?/g, ']').
replace(/(?:^|:|,)(?:s*[)+/g, ''))) {

  //the json is ok

}else{

  //the json is not ok

}
Comment

PREVIOUS NEXT
Code Example
Javascript :: js regex validate phone number 
Javascript :: node js remove html tags from string 
Javascript :: react native animated sticker 
Javascript :: jquery cdn cloudflare 
Javascript :: jquery replace element 
Javascript :: warning ../../../package.json no license field 
Javascript :: javascript detect touch screen 
Javascript :: get text selected option jquery 
Javascript :: trigger change select element jquery 
Javascript :: install moment in goole dev console 
Javascript :: kill all npm processes 
Javascript :: uppercase javascript 
Javascript :: javascript add attribute 
Javascript :: js set important style 
Javascript :: how to remove the parent div from the child in jquery 
Javascript :: remove first select option jquery 
Javascript :: sort array of object js 
Javascript :: req.body is undefined 
Javascript :: loop through key value pairs js 
Javascript :: jquery remove br from div 
Javascript :: timeout javascript 
Javascript :: set width of jqgrid 
Javascript :: turn object into string javascript 
Javascript :: sequelize exclude attribute 
Javascript :: round till 2 digit in jquery 
Javascript :: javascript stop setinterval 
Javascript :: install emailjs npm 
Javascript :: how to find prime numbers in an array in javascript 
Javascript :: javascript get string between two characters 
Javascript :: js method string remove extra spaces 
ADD CONTENT
Topic
Content
Source link
Name
4+3 =