Convert to XML or JSON data with advanced options

View as MarkdownMarkdown

Set up your AI agent

Give your coding agent live access to the GroupDocs documentation and API reference through the GroupDocs Docs MCP server — no install, no API key. Learn more

claude mcp add --transport http groupdocs-docs https://docs.groupdocs.com/mcp

Also process documents locally

The GroupDocs.Conversion MCP server lets your agent work with files on your machine; they are never uploaded. It needs the .NET 10 SDK or Docker.

claude mcp add groupdocs-conversion -- dnx GroupDocs.Conversion.Mcp --yes
Folders, licensing and more →

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.