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 :: pure-javascript-listen-to-input-value-change 
Javascript :: add operator in javascript 
Javascript :: enum in javascript es6 
Javascript :: socket io across two different ports 
Javascript :: does mysql accept json 
Javascript :: select div with specific class not all divs jquery 
Javascript :: pdf extract text nodejs 
Javascript :: occurences of special character in a string javascript 
Javascript :: change env location react 
Javascript :: php vscode editor.rulers vetical line delimiter line 
Javascript :: pass control id to javascript function 
Javascript :: Copy an Array with the Spread Operator 
Javascript :: vscode new file crlf 
Javascript :: array destructuring in js 
Javascript :: concatenate strings jsonata 
Javascript :: how to do multiple pages in angular 
Javascript :: using for loops to add an event listener 
Javascript :: scriptcase javascript close modal form 
Javascript :: // Write a function that takes two numbers (a and b) as argument // Sum a and b // Return the result 
Javascript :: javascript use numbers as objects 
Javascript :: vanilla javascript event when reach bottom of element no jquery 
Javascript :: Keyframe Overshoot 
Javascript :: blockchain.info/pushtx/ 
Javascript :: js download video element 
Javascript :: react spring bounce in animation 
Javascript :: jquery init dropdown 
Javascript :: html document from string javascript 
Javascript :: _.extend Example 
Javascript :: ajaxpost 
Javascript :: say something in console javascript 
ADD CONTENT
Topic
Content
Source link
Name
6+6 =