---
title: "quote_json"
url: https://una-lang.org/en/docs/std/prelude/quote_json/
release: v0.4.0
edition: "0.2 and later"
source: https://github.com/una-lang/una/blob/v0.4.0/docs/std/listing.json
---

# quote_json

A function of the prelude, in scope in every module. Edition 0.2 and later.

```una
pub quote_json(t: Text) -> Text
```

`t` 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

[`to_json`](https://una-lang.org/en/docs/std/prelude/to_json/)

## Example

`src/shop.una`

```una
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:

```text
"Desk \"lamp\"\tblue"
```

## Specification

- [`spec/23 §4`](https://una-lang.org/en/docs/spec/23-json/#s4)

Generated from the standard modules of una v0.4.0 ([`docs/std/listing.json`](https://github.com/una-lang/una/blob/5fec93d88932b333feec25e589355a2cb34c37b5/docs/std/listing.json), which is not part of the specification). The specification governs: [`spec/14 §1`](https://una-lang.org/en/docs/spec/14-standard-library/#s1).
