JSONBuilder { public JSONBuilder object(String key) { JSONBuilder subBuilder = new JSONBuilder(); data.put(key, subBuilder.data); return subBuilder; }  JSONBuilder put(String key, @Nullable Object value); JSONBuilder put(String key, @Nullable Instant value); JSONBuilder put(String key, @Nullable Duration value); JSONBuilder putBase64(String key, byte[] data); JSONBuilder putKey(String key, PublicKey publickey); JSONBuilder object(String key); JSONBuilder array(String key, Collection<?> values); Map<String, Object> toMap(); JSON toJSON(); @Override String toString();  }
@Test public void testObject() { JSONBuilder cb = new JSONBuilder(); JSONBuilder sub = cb.object("sub"); assertThat(sub, not(sameInstance(cb))); assertThat(cb.toString(), is("{\"sub\":{}}")); cb.put("foo", 123); sub.put("foo", 456); assertThat(cb.toString(), is("{\"sub\":{\"foo\":456},\"foo\":123}")); }