There are 2 options: raw and text.with(font: "monospacedfont"). First one only works on strings, second works on strings and content types. Usually you would use raw one way or another, but here a conversion from content to str should be added that is relatively robust and easy:
#import "@preview/t4t:0.4.2": get
#let format(xlist, level: 0) = {
if type(xlist) == dictionary {
xlist.values().map(get.text).map(raw).join("\n")
} else if type(xlist) == array {
xlist.map(example => (format(example, level: level + 1),)).join()
}
}
But if you will only ever use strings, then you don’t need that package function.
The less idiomatic way:
#let format(xlist, level: 0) = {
if type(xlist) == dictionary {
xlist.values().map(text.with(font: "Liberation Mono")).join("\n")
} else if type(xlist) == array {
xlist.map(example => (format(example, level: level + 1),)).join()
}
}
Of course, if you need to, you can move out the formatting function into an input parameter like @bluss showed above.