Answers for "valid json"

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
-1

javascript is valid json string

function isValidJSONString(str) {
    try {
        JSON.parse(str);
    } catch (e) {
        return false;
    }
    return true;
}
//usage
var personJSONString = '{"first_name":"Tony","last_name":"Hawk","age":31}';
if(isValidJSONString(personJSONString)){
 //cool we are valid, lets parse
 var person= JSON.parse(personJSONString);
}
Posted by: Guest on August-02-2019
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 validate

#convert column to string
df['movie_title'] = df['movie_title'].astype(str)

#but it remove numbers in names of movies too
df['titles'] = df['movie_title'].str.extract('([a-zA-Z ]+)', expand=False).str.strip()
df['titles1'] = df['movie_title'].str.split('(', 1).str[0].str.strip()
df['titles2'] = df['movie_title'].str.replace(r'\([^)]*\)', '').str.strip()
print df
          movie_title      titles      titles1      titles2
0  Toy Story 2 (1995)   Toy Story  Toy Story 2  Toy Story 2
1    GoldenEye (1995)   GoldenEye    GoldenEye    GoldenEye
2   Four Rooms (1995)  Four Rooms   Four Rooms   Four Rooms
3   Get Shorty (1995)  Get Shorty   Get Shorty   Get Shorty
4      Copycat (1995)     Copycat      Copycat      Copycat
Posted by: Guest on April-07-2021
0

como validar un json

let textoJSON = '{ "delegacionId": "0091" <<<ERROR>>> "places": ["Africa", "America", "Asia", "Australia"] }',
    objeto;

try {
    objeto = JSON.parse(textoJSON);
    console.log('Sintaxis Correcta');
}
catch (error) {
    if(error instanceof SyntaxError) {
        let mensaje = error.message;
        console.log('ERROR EN LA SINTAXIS:', mensaje);
    } else {
        throw error; // si es otro error, que lo siga lanzando
    }
}
Posted by: Guest on June-07-2021
0

JSON validate

S=pd.Series(['Finland','Colombia','Florida','Japan','Puerto Rico','Russia','france'])
[itm[0] for itm in S.str.findall('^[Ff].*') if len(itm)>0]
Posted by: Guest on July-01-2020

Browse Popular Code Answers by Language