Home / Docs / Standard library / Prelude
quote_json
A function of the prelude, in scope in every module. Edition 0.2 and later.
pub quote_json(t: Text) -> Textt as a JSON string literal (spec/23 §4 rule 2).
Parameters
t: the text
Returns
Text: t as a JSON string literal, between double quotes: the double quote and the backslash are escaped with a backslash; U+0008, U+000C, U+000A, U+000D and U+0009 are written as their short escapes; every other scalar value below U+0020, and U+007F, U+2028, U+2029, U+202A to U+202E and U+2066 to U+2069, as a u escape with four lowercase hex digits; and every other scalar value as itself; the result carries the labels of t (spec/23 §5); it escapes for a JSON string only, not for HTML, so <, >, & and / are written as themselves.
See also
Example
module shop
--- An item's name as a JSON string, with its quotes and its tab escaped.
pub main() -> Unit
uses @console: Console[print]
=
let quoted = quote_json("Desk \"lamp\"\tblue")
@console.print(quoted)una run . prints:
"Desk \"lamp\"\tblue"Specification
Generated from the standard modules of una v0.4.0 (docs/std/listing.json, which is not part of the specification). The specification governs: spec/14 §1.