Java Is Json isJSONValid(final String json)

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

Description

is JSON Valid

License

Open Source License

Declaration

public static boolean isJSONValid(final String json) 

Method Source Code


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

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

import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.IOException;

public class Main {
    public static boolean isJSONValid(final String json) {
        boolean valid = false;
        try {/*from  ww  w .  j a va 2 s .c om*/
            final JsonParser parser = new ObjectMapper().getFactory().createParser(json);
            while (parser.nextToken() != null) {
                // empty!
            }
            valid = true;
        } catch (JsonParseException jpe) {
            jpe.printStackTrace();
        } catch (IOException ioe) {
            ioe.printStackTrace();
        }

        return valid;
    }
}

Related

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