Deno.js Tutorial to Validate JSON Objects Schema Using isJSON Module Using TypeScript Full Project For Beginners

 

isJSON

 

 

Check if the string is a valid JSON structure

 

import the module in your deno app

import { isJSON } from 'https://deno.land/x/is_json@v1.0.2/mod.ts'

or from nest.land packages

import { isJSON } from 'https://x.nest.land/is_json@v1.0.2/mod.ts'

Usage:

console.log(isJSON('{"username": "moncefplastin07"}'))                 // true
console.log(isJSON('{"favoriteColors": ["red", "green", "black"]}'))   // true
const users = '[{"username": "moncefplastin07", "favoriteColors": ["red", "green", "black"]},{"username": "moncefplastin08", "favoriteColors": ["yellow", "green", "blue"]}]'
console.log(isJSON(users))                                             // true

console.log(isJSON("{'username': 'moncefplastin07'}"))                 // false
console.log(isJSON(12))                                                // false
console.log(isJSON({isAdmin: true}))

Leave a Reply