Here you can find the source of isValidJSON(final String json)
Parameter | Description |
---|---|
json | a parameter |
Parameter | Description |
---|---|
IOException | an exception |
public static boolean isValidJSON(final String json) throws IOException
//package com.java2s; //License from project: Open Source License import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import java.io.IOException; public class Main { /**/*from w w w . j ava2s . c o m*/ * check the string is a valid json string * @param json * @return * @throws IOException */ public static boolean isValidJSON(final String json) throws IOException { boolean valid = true; try { ObjectMapper mapper = new ObjectMapper(); mapper.readTree(json); } catch (JsonProcessingException e) { valid = false; } return valid; } }