Convert to XML or JSON data with advanced options

GroupDocs.Conversion enables converting documents to web data formats such as JSON and XML with advanced customization options through the WebConvertOptions class. This class allows precise control over the conversion process, including specifying the output format via the setFormat method.

Supported Formats

The conversion supports multiple web data formats. To convert documents into JSON or XML, you must set the Format property to either WebFileType.Json or WebFileType.Xml.

Convert CSV to JSON

Below is a code example demonstrating how to convert a CSV file to JSON format using

import com.groupdocs.conversion.Converter;
import com.groupdocs.conversion.options.convert.WebConvertOptions;
import com.groupdocs.conversion.filetypes.WebFileType;

public class ConvertCsvToJson {
    public static void convert() {
        // Initialize the Converter for the input file
        try(Converter converter = new Converter("sample.csv") {
            // Set up WebConvertOptions with JSON format
            WebConvertOptions options = new WebConvertOptions();
            options.setFormat(WebFileType.Json);

            // Perform the conversion
            converter.convert("converted.json", options);
        }
    }

    public static void main(String[] args){
        convert();
    }
}

sample.csv is sample file used in this example. Click here to download it.

converted.json is converted JSON file. Click here to download it.

By utilizing these options, you can generate tailored XML or JSON outputs suitable for integration with other systems or APIs.