Skip to content

Tree Navigation

Jan Bernitt edited this page Jan 20, 2024 · 3 revisions

"Casting" to Node Types (casting does not check that actual document matches the target)

  • T as(Class<T extends JsonValue> type)
  • JsonList<T> asList(Class<T extends JsonValue> type)
  • JsonMap<V> asMap(Class<V extends JsonValue> type)
  • and more of similar kind...

Tree Navigation

  • JsonValue get(String path)
  • JsonObject getObject(String path)
  • JsonArray getArray(String path)
  • JsonNumber getNumber(String path)
  • JsonBoolean getBoolean(String path)
  • JsonValue get(int index)
  • and more of similar kind...

Drilling down...

JsonString str=root.getObject("a").getArray("b").getString(3)
// is the same as
JsonString str=root.getString("a.b[3]")

Traversing the actual tree to find nodes

  • JsonValue#node(): from virtual to actual JSON tree 🗱
  • JsonObect#find: return first matching JsonValue
  • JsonNode#visit: visit matching nodes
  • JsonNode#find: return first matching JsonNode
  • JsonNode#count: count matching nodes
Clone this wiki locally