Menu

gitpiper

isValidJSON javascript Code Snippet in 2024

typeintermediate

Last Updated: 20 April 2024

Checks if the provided string is a valid JSON.

  • Use JSON.parse() and a try... catch block to check if the provided string is a valid JSON.
const isValidJSON = str => { try { JSON.parse(str); return true; } catch (e) { return false; } };
isValidJSON('{"name":"Adam","age":20}'); // true isValidJSON('{"name":"Adam",age:"20"}'); // false isValidJSON(null); // true

javascript snippet similar to isValidJSON For You in April 2024

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️

© 2024 GitPiper. All rights reserved

Rackpiper Technology Inc

Company

About UsBlogContact

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️