Skip to content

Latest commit

 

History

History
57 lines (43 loc) · 1.43 KB

README.md

File metadata and controls

57 lines (43 loc) · 1.43 KB

Javason

Javason is a Java DSL that makes it easy to specify JSON directly inside of Java source code. This provides an alternative to unreadable, difficult-to-format strings riddled with escape characters like this:

String testPayload = "{" +
    "\"key\": \"value\"," +
    "\"with\": {" +
        "\"escapeCharacters\": true" +
    "}" +
"}";

Instead, Javason allows you to write the following:

String testPayload = json(
    key -> "value",
    with -> json(
        escapeCharacters -> true
    )
).toString();

With Javason, you're guaranteed to produce valid JSON, because Javason is Java 8 code that will be checked by the compiler. Additionally, Javason is more readable than string literals and can be formatted by standard Java code formatters.

Installation

Javason is available as a Maven repository through JitPack.

Limitations

Because Javason keys are Java parameters, they are limited to being valid Java identifiers. Additionally, because of restrictions on the Java 8 syntax, the keys cannot conflict with any variables in scope.

Requirements

Javason depends on bug fixes in Java 8u60 and cannot be used with any prior versions of Java.

Credits

Javason was inspired by an article by Benji Weber.