Java Is Json isValidJSON(final String json)

Here you can find the source of isValidJSON(final String json)

Description

is Valid JSON

License

Open Source License

Declaration

public static boolean isValidJSON(final String json) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.IOException;

import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.ObjectMapper;

public class Main {
    public static boolean isValidJSON(final String json) {
        try {/*  w  w w.j a  v  a2  s.com*/
            final JsonParser parser = new ObjectMapper().getFactory()
                    .createParser(json);
            while (parser.nextToken() != null) {
            }
            return true;
        } catch (JsonParseException jpe) {
            return false;
        } catch (IOException ioe) {
            return false;
        }

    }
}

Related

  1. isJSONValid(String jsonInString)
  2. isJSONValid(final String json)
  3. isJSONEqual(M expectedJSON, N actualJSON)
  4. isValidJSON(final String json)
  5. isValidJSON(final String json)