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

# JsonNumber

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

```una
pub kind JsonNumber = Text where is_json_number(it)
```

The text of a JSON number with a fraction or an exponent, which `Decimal` holds (`spec/23 §1`).

## Definition

`Text where is_json_number(it)`: the text of a JSON number with a fraction or an exponent\, as `Decimal` holds it\; since `is_json_number` is opaque\, a `JsonNumber` is made by parsing\, or in code by `checked`.

## See also

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

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