j

jsonpath

@preview

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

v0.1.0
MIT

Package Information

Last Updated
Minimum Typst Version
0.13.1
Authors
Jebbs
Categories
scriptingutility

1. Get the package

Download the package using the TPIX CLI:

tpix get @preview/jsonpath:0.1.0

2. Import in your Typst file

Add this to your .typ file:

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

Version History

0.1.00.13.1
b3a2bdac3247...

jsonpath

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.