> Java lacks the expressiveness to make it much better than this.
That's not really true. You can have a Java library providing:
Json.writeTo(System.out)
.object()
.array("providers")
.element("SUN")
.element("SunRsaSign")
.element("SunEC")
.end()
.end();
or as a shortcut Json.writeTo(System.out)
.object()
.array("providers").withElements("SUN", "SunRsaSign", "SunEC")
.end();
or similar (aka faceted fluent API), with typed interfaces mirroring the grammar of the target language, here JSON.This is basically a structured output iterator (or OutputStream-like) pattern. It can also support modularization such that substructures can be factored out into separate methods or lambdas, thereby also allowing loops and conditionals.
Such an API can be provided in a relatively compact fashion and would be nicer than what the JEP proposes.