Fork me on GitHub
#java
<
2022-11-11
>
emccue03:11:23

I cloned a chunk of clojure.data.json into Java for fun. Main differences are no writer protocol and obv. reads into a custom Json tree and not data primitives

public class Main {
    public static void main(String[] args) {
        var jsonA = Json.readString("""
                {
                    "hello": [
                        "world"
                    ],
                    "abc": 123
                }
                """);

        var jsonB = Json.objectBuilder()
                .put("hello", Json.arrayBuilder()
                        .add(Json.of("world"))
                        .build())
                .put("abc", Json.of(123))
                .build();

        var written = Json.writeString(
                Json.of(List.of(jsonA, jsonB)),
                new Json.WriteOptions()
                        .withIndent(true)
        );


        System.out.println(written);
    }
}