string json or not

    0

    0

    Mansimar Anand

    Check is the string is JSON or not in JavaScript

    function isJSON(str) {
      try {
          JSON.parse(str)
      }
      catch {
          return false
      }
    	return true
    }
    var str = "JavaScript"
    console.log(isJSON(str))
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Explore
    • Cookbooks
    • Playground
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.