Java: Text Blocks + String#formatted = JSON 📎
String#formatted
allow inline creation of JSON objects with plain Java:
@Test
public void generateJson() {
var message = """
{
"message":"%s"
}
""".formatted("hello,duke");
System.out.println(message);
}
The code above prints:
{
"message":"hello,duke"
}