How to Validate JSON File using Java

2 min readJun 29, 2022


Since JSON files are one of the most common, interoperable data-transfer file formats available to us, it’s critically important to ensure those files are correctly structured before unwittingly creating bigger data processing problems down the line. Our JSON Validation API will let you know instantaneously if a JSON file was password-protected or invalid, and if invalid, detailed information including the description, path and URI will be provided. To help you structure an API call in Java, we’ve provided ready-to-run code examples and instructions below. At the bottom of this article, I’ve copied an example response model for your reference as well.

Let’s first install the Java SDK. Add a reference to the repository in pom.xml:


Next, let’s add a reference to the dependency in pom.xml:


Finally, let’s make our API call. Add the imports at the top of your file first, and then call the API:

// Import classes:
//import com.cloudmersive.client.invoker.ApiClient;
//import com.cloudmersive.client.invoker.ApiException;
//import com.cloudmersive.client.invoker.Configuration;
//import com.cloudmersive.client.invoker.auth.*;
//import com.cloudmersive.client.ValidateDocumentApi;
ApiClient defaultClient = Configuration.getDefaultApiClient();// Configure API key authorization: Apikey
ApiKeyAuth Apikey = (ApiKeyAuth) defaultClient.getAuthentication("Apikey");
Apikey.setApiKey("YOUR API KEY");
// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)
ValidateDocumentApi apiInstance = new ValidateDocumentApi();
File inputFile = new File("/path/to/inputfile"); // File | Input file to perform the operation on.
try {
DocumentValidationResult result = apiInstance.validateDocumentJsonValidation(inputFile);
} catch (ApiException e) {
System.err.println("Exception when calling ValidateDocumentApi#validateDocumentJsonValidation");

Your parameters include your input file, and your Cloudmersive API key. If you don’t have a key, you can easily get one for free by registering a free account on our website. With your account, you’ll receive a limit of 800 API calls per month.




There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.