Answers for "js test if string is json"

1

check if the data can be parsed javascript

function isJson(str) {
            try {
                return JSON.parse(str);
            } catch (e) {
                return false;
            }
        }
Posted by: Guest on July-24-2020
1

if json then parse

function isJson(str) {
    try {
        let value = JSON.parse(str);
      	return value
    } catch (e) {
        return str;
    }
}
Posted by: Guest on November-03-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language