To convert your object in JSON with Jackson:

import com.fasterxml.jackson.databind.ObjectMapper; 
import com.fasterxml.jackson.databind.ObjectWriter; 

ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter();
String json = ow.writeValueAsString(object);
Answer from Jean Logeart on Stack Overflow
🌐
Json2CSharp
json2csharp.com β€Ί code-converters β€Ί json-to-pojo
Convert JSON to POJO Objects in Java Online
Here's how you can convert your ... example: HERE Β· Make sure that your JSON object is not large (over 5MB) and is formatted. You can use any JSON format validator online....
🌐
Javatojson
javatojson.com
Java toString to JSON Converter | Free Online Tool
Convert Java toString() output to JSON format instantly. Free, fast, and secure online tool for Java developers.
Top answer
1 of 11
714

To convert your object in JSON with Jackson:

import com.fasterxml.jackson.databind.ObjectMapper; 
import com.fasterxml.jackson.databind.ObjectWriter; 

ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter();
String json = ow.writeValueAsString(object);
2 of 11
57

I know this is old (and I am new to java), but I ran into the same problem. And the answers were not as clear to me as a newbie... so I thought I would add what I learned.

I used a third-party library to aid in the endeavor: org.codehaus.jackson All of the downloads for this can be found here.

For base JSON functionality, you need to add the following jars to your project's libraries: jackson-mapper-asl and jackson-core-asl

Choose the version your project needs. (Typically you can go with the latest stable build).

Once they are imported in to your project's libraries, add the following import lines to your code:

 import org.codehaus.jackson.JsonGenerationException;
 import org.codehaus.jackson.map.JsonMappingException;
 import com.fasterxml.jackson.databind.ObjectMapper;

With the java object defined and assigned values that you wish to convert to JSON and return as part of a RESTful web service

User u = new User();
u.firstName = "Sample";
u.lastName = "User";
u.email = "[email protected]";

ObjectMapper mapper = new ObjectMapper();
    
try {
    // convert user object to json string and return it 
    return mapper.writeValueAsString(u);
}
catch (JsonGenerationException | JsonMappingException  e) {
    // catch various errors
    e.printStackTrace();
}

The result should looks like this: {"firstName":"Sample","lastName":"User","email":"[email protected]"}

🌐
Online Tools
onlinetools.com β€Ί json β€Ί convert-properties-to-json
Convert Properties to JSON – Online JSON Tools
The tool supports both the classic (Java) and custom properties file formats. The classic properties file format uses the equals sign or a colon ("=" or ":") to separate keys and values, a dot "." to separate keys in nested objects and indexes in nested arrays. For example, a classic properties file "cat=Luna" is converted to a JSON object { "cat" : "Luna" }. Similarly, the properties file "cat.name=Luna" is converted to a JSON object containing another nested object { "cat" : { "name" : "Luna" } }, and the properties file "cat.0=Luna" is converted to a JSON object containing a nested array { "cat" : [ "Luna" ] }. If your properties file uses different separator symbols, you can switch to the custom properties file format and set the separators in the options fields.
🌐
JSON Formatter
jsonformatter.org β€Ί 0564a5
pojo
JSON Format Checker helps to fix the missing quotes, click the setting icon which looks like a screwdriver on the left side of the editor to fix the format. ... JSON Example with all data types including JSON Array. ... Online JSON Formatter and Online JSON Validator provide JSON converter tools to convert JSON to XML, JSON to CSV, and JSON to YAML also JSON Editor, JSONLint, JSON Checker, and JSON Cleaner.
🌐
JavaTechOnline
javatechonline.com β€Ί home β€Ί how to convert java object to json?
How To Convert Java Object To JSON? And JSON To Java?
May 1, 2025 - We can parse JSON data in Java using libraries like Jackson, Gson, or org.json. These libraries provide APIs for reading JSON data and converting it into Java objects. Additionally, to convert Java objects into JSON format, we can use JSON libraries such as Jackson, Gson, or org.json.
Find elsewhere
🌐
JetBrains
plugins.jetbrains.com β€Ί plugin β€Ί 14603-java-json-convertor
Java Json Convertor - IntelliJ IDEs Plugin | Marketplace
Plugin to convert Json file to Java file and vice versa. Java To Json Converter 1. Place the Java file into any java package. 2. Right-click on valid Java pojo file...
🌐
Javatpoint
javatpoint.com β€Ί convert-java-object-to-json
Convert Java object to JSON - javatpoint
Convert Java object to JSON with java tutorial, features, history, variables, object, programs, operators, oops concept, array, string, map, math, methods, examples etc.
🌐
Tabnine
tabnine.com β€Ί home β€Ί convert java object to json
Convert Java object to JSON - Tabnine
July 25, 2024 - Use the JACKSON API: ObjectMapper mapper class: call writeValueAsString(ObjToConvert) method by passing the object we want to convert into JSON or Use GSON API: class Gson: call toJson(ObjToConvert) method by passing the object we want to convert ...
🌐
Freecodeformat
freecodeformat.com β€Ί json2pojo.php
JSON to POJO (Java) Converter - Generate Java POJO Classes Online
It analyzes data types, handles nested objects, manages arrays, and integrates with modern Java ecosystems like Lombok and serialization frameworks. Instant Conversion: Zero delay between JSON input and Java output. Lombok Support: Reduce boilerplate with @Data and @Builder. Annotation Ready: Full support for Jackson, Gson, and Fastjson. ... Paste your raw JSON response into the left editor panel. ... Set your package name, choose Lombok style, or select your preferred JSON library.
🌐
Code Beautify
codebeautify.org β€Ί json-to-java-converter
JSON to JAVA Converter: Convert JSON to JAVA Class
This tool will help you to convert your JSON String/Data to JAVA Class Object. This tool allows loading the JSON URL, which loads JSON and converts to Java. Click on the URL button, Enter URL and Submit. Users can also Convert JSON File to Java by uploading the file. When you are done with JSON to Java converting. You can download as a file or create a link and share. JSON to java Online works well on Windows, MAC, Linux, Chrome, Firefox, Edge, and Safari.
🌐
JavaTechOnline
javatechonline.com β€Ί home β€Ί java pojo to json online
Java Pojo To Json Online Archives - JavaTechOnline
Almost everyone in the software industry directly or indirectly, sooner or later get a chance to work with JSON. Now you can imagine how important it is to know in & out of it. You may have a question in your mind ' How to convert Java Object to JSON' and 'How to convert JSON to Java Object?'. Although JSON syntax is very easy to write, but sometimes it creates confusion when an object is a bit complex.
🌐
Minifier
minifier.org β€Ί json-to-java
Convert JSON to Java Object Online
JSON to JAVA Converter is an online tool that transforms JSON data into JAVA. It simplifies converting JSON data into Java making it easy for developers to focus more on application logic and less on data conversion complexities.
🌐
Educative
educative.io β€Ί answers β€Ί how-to-convert-a-java-object-to-json
How to convert a Java object to JSON
The Google GSON​ library is the most popular library used for converting Java objects to JSON.
🌐
Medium
medium.com β€Ί @salvipriya97 β€Ί how-to-convert-java-pojo-to-json-using-jackson-2ef9b69c4f08
How to convert Java POJO to JSON using Jackson | by Priya Salvi | Medium
April 28, 2024 - Use the writeValueAsString() method of the ObjectMapper instance to serialize the Java object to JSON format. Here’s how you can convert the Person class to JSON using Jackson:
🌐
Jsonschema2pojo
jsonschema2pojo.org
jsonschema2pojo
Generate Plain Old Java Objects from JSON or JSON-Schema. ... For each property present in the 'properties' definition, we add a property to a given Java class according to the JavaBeans spec.
Top answer
1 of 1
2

Why not use GeoTools to handle the input and output? Then your code becomes simply something like:

File inFile = new File("/home/ian/Data/states/states.shp");
File outFile = new File("/home/ian/Data/states/states.geojson");
if (outFile.exists()) {
  outFile.delete();
}
outFile.createNewFile();
// Read
DataStore inputDataStore = DataStoreFinder.getDataStore(
        Collections.singletonMap("url", URLs.fileToUrl(inFile)));

String inputTypeName = inputDataStore.getTypeNames()[0];
SimpleFeatureType inputType = inputDataStore.getSchema(inputTypeName);

FeatureSource<SimpleFeatureType, SimpleFeature>
        source = inputDataStore.getFeatureSource(inputTypeName);

FeatureCollection<SimpleFeatureType, SimpleFeature>
        inputFeatureCollection = source.getFeatures();

Map<String, Object> params = new HashMap<>();
params.put(GeoJSONDataStoreFactory.URLP.key, URLs.fileToUrl(outFile));
// Write
DataStore newDataStore = DataStoreFinder.getDataStore(params);

newDataStore.createSchema(inputType);
String typeName = newDataStore.getTypeNames()[0];

SimpleFeatureStore featureStore =
        (SimpleFeatureStore) newDataStore.getFeatureSource(typeName);

featureStore.addFeatures(inputFeatureCollection);
newDataStore.dispose();
inputDataStore.dispose();

}

If you don't want to export all the attributes of the shapefile features you need to modify newDataStore.createSchema(inputType); to use a new limited schema. This needs something like:

SimpleFeatureType outType = DataUtilities.createSubType(inputType, new String[] {"type","REFCAT"});
newDataStore.createSchema(outType);