Overview

Cutlet is a “batteries included” library to make working directly with XML and JSON as data structures in Java simpler.

Non goals:

Examples

Hello world in JSON:

JSON.create().add("message").with("hello", "world")

creates:

{
  "message": {
    "hello": "world"
  }
}

Hello world in XML:

XML.create("message").with("hello", "world")

creates:

<message>
    <hello>world</hello>
</message>

More complex: Given an XML file containing a list of people and their home and mobile phone numbers (input.xml), output a JSON associative array of their mobile phone numbers to names, changing the keys for “firstname” and “lastname” to “forename” and “surname” (output.json):

JSON output = JSON.create();
XML.parseFile("input.xml").getList("person").forEach(person -> 
    output.add("mobile-" + person.getString("phonenumber[@type = 'mobile']"))
        .withString("forename", person.getString("firstname"))
        .withString("surname", person.getString("lastname")));
String json = output.write(PRETTY);

See the JSON and XML tests cases for more examples.

Downloading

Current version is 0.4 - alpha quality code (API is subject to change).

Maven:

<dependency>
  <groupId>com.snell.michael.cutlet</groupId>
  <artifactId>cutlet</artifactId>
  <version>0.4</version>
</dependency>

Direct download: http://repo1.maven.org/maven2/com/snell/michael/cutlet/cutlet

Fine print