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

# is_json_number

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

```una
pub predicate opaque is_json_number(t: Text) -> Bool
```

Whether `t` is one JSON number of RFC 8259 §6 (`spec/23 §1`). Opaque: both engines evaluate it.

## Parameters

- `t`: the text

## Returns

`Bool`: `true` exactly when `t` is one JSON number of RFC 8259 §6 with a fraction or an exponent\; opaque\: both engines evaluate it\, and the verifier knows nothing more of it\, so in code it is called only as the predicate of `checked`\, and elsewhere in code is U2016\; a kind\'s `where` clause\, as in `JsonNumber`\, the `requires` and `ensures` of a capability operation\, and the body of another opaque predicate may name it \(`spec/03 §4`\, ADR 0042\)\; `checked` counts against `[escape_budget] checked_per_module`\, which is 0 unless `una.toml` raises it.

## See also

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

## Example

`src/shop.una`

```una
module shop

--- A price typed by hand, kept as a `JsonNumber` when it has a fraction or an exponent.
kind PriceError = | NotDecimal

priced(raw: Text) -> JsonNumber
  fails PriceError
=
  checked(raw, is_json_number(it)) else fail NotDecimal

shown(raw: Text) -> Text
=
  let outcome = attempt priced(raw)
  when outcome
    is Ok(price) -> "price {price}"
    else -> "{raw} is not a decimal"

pub main() -> Unit
  uses @console: Console[print]
=
  @console.print(shown("9.95"))
  @console.print(shown("12"))
  @console.print(shown("1.5e3"))
```

`una run .` prints:

```text
price 9.95
12 is not a decimal
price 1.5e3
```

## Specification

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

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).
