Answers for "json checker"

PHP
8

if json valide js

function IsJsonString(str) {
    try {
        JSON.parse(str);
    } catch (e) {
        return false;
    }
    return true;
}
Posted by: Guest on April-10-2020
0

how to verify json format is valid

I use Gson class in order to convert a
Json object into a java object.
If it works without any error, it means that it is a valid json format...

import com.google.gson.Gson;

public class JSONUtils {

  Gson gson = new Gson();

  public boolean isJSONValid(String jsonInString) {
      try {
          gson.fromJson(jsonInString, Object.class);   
          return true;
      } catch(com.google.gson.JsonSyntaxException e) { 
          return false;
      }
  }
}
Posted by: Guest on January-14-2021
0

json data check

import json

studentJson ="""{
   "id": 1,
   "name": "john wick",
   "class": null,
   "percentage": 75,
   "email": "[email protected]"
}"""
student = json.loads(studentJson)
if not (student.get('email') is None):
     print("value is present for given JSON key")
     print(student.get('email'))
else:
    print("value is not present for given JSON key")
Posted by: Guest on August-28-2021

Browse Popular Code Answers by Language