https://www.generatesourcecode.co.in/

Developer Productivity Tools

JSON ↔ XML Converter

Convert JSON to XML or XML to JSON instantly. Copy, download, email or share the generated result.

Input

Paste JSON or XML

Output

Generated result

🚀 How to Use

  1. Select JSON → XML or XML → JSON.
  2. Paste your input into the Input text area.
  3. Click Generate.
  4. The converted result will appear in the Output area.
  5. Use Copy, Download, Email or Share as required.

Supported Example

{ "employee": { "id": 101, "name": "Ashutosh", "department": "IT", "skills": [ "Java", "Spring Boot", "REST API" ] } }

☕ Use RESTful Class in Spring Boot

The generated JSON/XML can be used while developing Spring Boot RESTful services.

1. Create REST Controller

package com.example.demo.controller; import org.springframework.web.bind.annotation.*; @RestController @RequestMapping("/api") public class EmployeeController { @GetMapping( value = "/employee", produces = "application/json" ) public Employee getEmployee() { Employee employee = new Employee(); employee.setId(101L); employee.setName("Ashutosh"); employee.setDepartment("IT"); employee.setSalary(75000); return employee; } }

2. Create POJO Class

public class Employee { private Long id; private String name; private String department; private double salary; public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getDepartment() { return department; } public void setDepartment(String department) { this.department = department; } public double getSalary() { return salary; } public void setSalary(double salary) { this.salary = salary; } }

📦 Spring Boot POST Example

If the converted JSON is required as the request body of a REST API, use @RequestBody.

@PostMapping( value = "/employee", consumes = "application/json", produces = "application/json" ) public Employee createEmployee( @RequestBody Employee employee) { return employee; }

Sample Request

POST http://localhost:8080/api/employee Content-Type: application/json { "id": 101, "name": "Ashutosh", "department": "IT", "salary": 75000 }

Test with Postman

  • Open Postman.
  • Select POST.
  • Enter the Spring Boot REST URL.
  • Select Body → raw → JSON.
  • Paste the generated JSON.
  • Click Send.

🔄 XML REST API Example

Spring Boot can also consume and produce XML when the appropriate XML message converter/dependency is configured.

@GetMapping( value = "/employee", produces = "application/xml" ) public Employee getEmployeeXml() { Employee employee = new Employee(); employee.setId(101L); employee.setName("Ashutosh"); employee.setDepartment("IT"); employee.setSalary(75000); return employee; }

Example XML

<employee> <id>101</id> <name>Ashutosh</name> <department>IT</department> <salary>75000</salary> </employee>

The converter on this page can be used to quickly transform payloads between JSON and XML while developing or testing REST APIs.