Universe

jsonpath extracts values from dictionary or array using a JSONPath expression as per RFC 9535, except the filter syntax is different.

Examples

Import the package jsonpath before using it.

#import "@preview/jsonpath:0.1.0": *

Extract all titles of books from the store.

#{
  let obj = json("rfc9535-1-5.json")
  let result = json-path(obj, "$.store.book.*.title")
}

Filter elements using custom filter functions.

#{
  let obj = (o: (1, 2, 3, 5, (u: 6)))
  // equivalent to "$.o[?@<3, ?@<3]" which is not supported.
  let result = json-path(
    obj,
    "$.o[?,?]", // or "$.o[?0,?0]",
    it => type(it) in (int, float) and it < 3,
  )
}

See jsonpath_test.typ for more examples.