jquery verify json string

+1 vote
222 views
asked May 11 in Jquery by Jasna
How to verify json string (if valid) with jquery?

1 Answer

0 votes
answered May 11 by anonymous
Us this to verify.

function isJSON(str) 
{
    if( typeof( str ) !== 'string' ) { 
        return false;
    }
    try {
        JSON.parse(str);
        return true;
    } catch (e) {
        return false;
    }
}

Related questions

0 votes
1 answer 231 views
asked Jul 29, 2016 in Phalcon by Robin
+2 votes
2 answers 518 views
...